mirror of
				https://github.com/johnwhitington/cpdf-source.git
				synced 2025-06-05 22:09:39 +02:00 
			
		
		
		
	-trim-marks finished
This commit is contained in:
		
							
								
								
									
										14
									
								
								Changes
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								Changes
									
									
									
									
									
								
							@@ -1,6 +1,20 @@
 | 
			
		||||
Version 2.3 (October 2019)
 | 
			
		||||
 | 
			
		||||
o Directly set and remove Trim, Art, and Bleed boxes
 | 
			
		||||
o Dump attachments to file
 | 
			
		||||
o New -hard-box option to set a box and clip to it
 | 
			
		||||
o Extended bookmark format, preserving all bookmark information
 | 
			
		||||
o New -pad-with, -pad-mutiple-before option
 | 
			
		||||
o Set or create XMP metadata
 | 
			
		||||
o -remove-clipping
 | 
			
		||||
o Extended support for reading malformed files
 | 
			
		||||
o Embed missing fonts by calling out to gs
 | 
			
		||||
o Set bookmarks open to a given level
 | 
			
		||||
o Create PDF files from scatch
 | 
			
		||||
o Remove single images by name
 | 
			
		||||
o Add trim and registration marks
 | 
			
		||||
o Merge AcroForms
 | 
			
		||||
o Search for unicode characters in a font automatically
 | 
			
		||||
 | 
			
		||||
Version 2.2 (patchlevel 1)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -186,6 +186,7 @@ type op =
 | 
			
		||||
  | CreatePDF
 | 
			
		||||
  | RemoveAllText
 | 
			
		||||
  | ShowBoxes
 | 
			
		||||
  | TrimMarks
 | 
			
		||||
 | 
			
		||||
let string_of_op = function
 | 
			
		||||
  | CopyFont _ -> "CopyFont"
 | 
			
		||||
@@ -305,6 +306,7 @@ let string_of_op = function
 | 
			
		||||
  | CreatePDF -> "CreatePDF"
 | 
			
		||||
  | RemoveAllText -> "RemoveAllText"
 | 
			
		||||
  | ShowBoxes -> "ShowBoxes"
 | 
			
		||||
  | TrimMarks -> "TrimMarks"
 | 
			
		||||
 | 
			
		||||
(* Inputs: filename, pagespec. *)
 | 
			
		||||
type input_kind =
 | 
			
		||||
@@ -656,7 +658,7 @@ let banned banlist = function
 | 
			
		||||
  | PrintPageLabels | Clean | Compress | Decompress
 | 
			
		||||
  | RemoveUnusedResources | ChangeId | CopyId _ | ListSpotColours | Version
 | 
			
		||||
  | DumpAttachedFiles | RemoveMetadata | EmbedMissingFonts | BookmarksOpenToLevel _ | CreatePDF
 | 
			
		||||
  | ShowBoxes -> false (* Always allowed *)
 | 
			
		||||
  | ShowBoxes | TrimMarks -> false (* Always allowed *)
 | 
			
		||||
  (* Combine pages is not allowed because we would not know where to get the
 | 
			
		||||
  -recrypt from -- the first or second file? *)
 | 
			
		||||
  | ExtractText | ExtractImages | ExtractFontFile
 | 
			
		||||
@@ -1828,6 +1830,9 @@ and specs =
 | 
			
		||||
   ("-show-boxes",
 | 
			
		||||
       Arg.Unit (setop ShowBoxes),
 | 
			
		||||
       " Show boxes by adding rectangles to pages");
 | 
			
		||||
   ("-trim-marks",
 | 
			
		||||
       Arg.Unit (setop TrimMarks),
 | 
			
		||||
       " Add trim marks");
 | 
			
		||||
   ("-remove-crop",
 | 
			
		||||
       Arg.Unit (setop RemoveCrop),
 | 
			
		||||
       " Remove cropping on specified pages");
 | 
			
		||||
@@ -3685,6 +3690,36 @@ let show_boxes_page pdf _ page =
 | 
			
		||||
let show_boxes range pdf =
 | 
			
		||||
  Cpdf.process_pages (show_boxes_page pdf) pdf range
 | 
			
		||||
 | 
			
		||||
let allowance = 9.
 | 
			
		||||
 | 
			
		||||
let line (x0, y0, x1, y1) =
 | 
			
		||||
  [Pdfops.Op_m (x0, y0);
 | 
			
		||||
   Pdfops.Op_l (x1, y1);
 | 
			
		||||
   Pdfops.Op_s]
 | 
			
		||||
 | 
			
		||||
let trim_marks_page pdf n page =
 | 
			
		||||
  match get_rectangle pdf page "/TrimBox", get_rectangle pdf page "/MediaBox" with
 | 
			
		||||
  | Some (tminx, tminy, tmaxx, tmaxy), Some (minx, miny, maxx, maxy) ->
 | 
			
		||||
      let ops =
 | 
			
		||||
        [Pdfops.Op_q;
 | 
			
		||||
         Pdfops.Op_K (1., 1., 1., 1.);
 | 
			
		||||
         Pdfops.Op_w 1.]
 | 
			
		||||
         @ line (minx, tmaxy, tminy -. allowance, tmaxy) (* top left *)
 | 
			
		||||
         @ line (tminx, tmaxy +. allowance, tminx, maxy)
 | 
			
		||||
         @ line (tmaxx +. allowance, tmaxy, maxx, tmaxy) (* top right *)
 | 
			
		||||
         @ line (tmaxx, tmaxy +. allowance, tmaxx, maxy)
 | 
			
		||||
         @ line (tmaxx +. allowance, tminy, maxx, tminy) (* bottom right *)
 | 
			
		||||
         @ line (tmaxx, tminy -. allowance, tmaxx, miny)
 | 
			
		||||
         @ line (tminx -. allowance, tminy, minx, tminy) (* bottom left *)
 | 
			
		||||
         @ line (tminx, tminy -. allowance, tminx, miny)
 | 
			
		||||
         @ [Pdfops.Op_Q]
 | 
			
		||||
      in
 | 
			
		||||
        Pdfpage.postpend_operators pdf ops ~fast:args.fast page
 | 
			
		||||
  | _, _ -> Printf.eprintf "-trim_marks: No /TrimBox found on page %i\n" n; page
 | 
			
		||||
 | 
			
		||||
let trim_marks range pdf =
 | 
			
		||||
  Cpdf.process_pages (trim_marks_page pdf) pdf range
 | 
			
		||||
 | 
			
		||||
(* Main function *)
 | 
			
		||||
let go () =
 | 
			
		||||
  match args.op with
 | 
			
		||||
@@ -4554,6 +4589,10 @@ let go () =
 | 
			
		||||
      let pdf = get_single_pdf args.op false in
 | 
			
		||||
      let range = parse_pagespec pdf (get_pagespec ()) in
 | 
			
		||||
        write_pdf false (show_boxes range pdf)
 | 
			
		||||
  | Some TrimMarks ->
 | 
			
		||||
      let pdf = get_single_pdf args.op false in
 | 
			
		||||
      let range = parse_pagespec pdf (get_pagespec ()) in
 | 
			
		||||
        write_pdf false (trim_marks range pdf)
 | 
			
		||||
 | 
			
		||||
let parse_argv () =
 | 
			
		||||
  if args.debug then
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,6 @@
 | 
			
		||||
%FIXME: Document new bookmark format + use of -utf8 for getting good bookmarks
 | 
			
		||||
%FIXME: Fix docs on -fit-window and friends
 | 
			
		||||
%FIXME: Document new -pad-with (for -pad-before, -pad-after, -pad-every)
 | 
			
		||||
%FIXME: Activate documentation for -extract-images (when done)
 | 
			
		||||
%FIXME: Document new -artbox, -trimbox, -bleedbox and -remove-artbox, -remove-trimbox, -remove-bleedbox
 | 
			
		||||
%FIXME: Document -cropbox and -remove-cropbox as synonyms of -crop and -remove-crop
 | 
			
		||||
%FIXME: Document new XMP metadata stuff including setmetadata date and its format
 | 
			
		||||
@@ -27,7 +26,7 @@
 | 
			
		||||
%FIXME: Explain fast more / better and list things it works on
 | 
			
		||||
%FIXME: Document new -draft-remove-only functionality for deleting images
 | 
			
		||||
%FIXME: Document that -decompress may need -no-preserve-objstm
 | 
			
		||||
%FIXME: Document new -show-boxes, -trim-marks, -registation-marks operations. 
 | 
			
		||||
%FIXME: Document new -show-boxes, -trim-marks operations. 
 | 
			
		||||
 | 
			
		||||
\documentclass{book}
 | 
			
		||||
\usepackage{palatino}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user