From bcef18797b071d6e83f2ca9a4fd501a843471a80 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 15 Jul 2019 13:42:32 +0100 Subject: [PATCH] -trim-marks finished --- Changes | 14 ++++++++++++++ cpdfcommand.ml | 41 ++++++++++++++++++++++++++++++++++++++++- cpdfmanual.tex | 3 +-- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 99150bc..7b00aa1 100644 --- a/Changes +++ b/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) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 45ec920..abe61e1 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -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 diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 100aea3..1214c6a 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -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}