mirror of
				https://github.com/johnwhitington/cpdf-source.git
				synced 2025-06-05 22:09:39 +02:00 
			
		
		
		
	demo gone
This commit is contained in:
		
							
								
								
									
										50
									
								
								cpdf.ml
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								cpdf.ml
									
									
									
									
									
								
							| @@ -2244,56 +2244,6 @@ let combine_pages fast under over scaletofit swap equalize = | |||||||
|                    debug_pdf r "final.pdf"; |                    debug_pdf r "final.pdf"; | ||||||
|                    r |                    r | ||||||
|  |  | ||||||
| let nobble_page pdf _ page = |  | ||||||
|   let minx, miny, maxx, maxy = |  | ||||||
|     (* Use cropbox if available *) |  | ||||||
|     Pdf.parse_rectangle |  | ||||||
|       (match Pdf.lookup_direct pdf "/CropBox" page.Pdfpage.rest with |  | ||||||
|        | Some r -> r |  | ||||||
|        | None -> page.Pdfpage.mediabox) |  | ||||||
|   in |  | ||||||
|     let fontdict = |  | ||||||
|       match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with |  | ||||||
|       | None -> Pdf.Dictionary [] |  | ||||||
|       | Some d -> d |  | ||||||
|     in |  | ||||||
|       let fontname = Pdf.unique_key "F" fontdict in |  | ||||||
|     let width = maxx -. minx in let height = maxy -. miny in |  | ||||||
|       let scalex = |  | ||||||
|         (width *. 1000.) /. float (Pdfstandard14.textwidth false Pdftext.StandardEncoding Pdftext.Helvetica "DEMO") |  | ||||||
|       in |  | ||||||
|         let page' = |  | ||||||
|           let font = |  | ||||||
|             Pdf.Dictionary |  | ||||||
|               [("/Type", Pdf.Name "/Font"); |  | ||||||
|                ("/Subtype", Pdf.Name "/Type1"); |  | ||||||
|                ("/BaseFont", Pdf.Name "/Helvetica")] |  | ||||||
|           in let ops = |  | ||||||
|             [Pdfops.Op_BMC "/CPDFSTAMP"; |  | ||||||
|              Pdfops.Op_cm |  | ||||||
|                (Pdftransform.matrix_of_transform |  | ||||||
|                   [Pdftransform.Translate (minx, miny +. height /. 2.)]); |  | ||||||
|              Pdfops.Op_gs "/gs0"; |  | ||||||
|              Pdfops.Op_BT; |  | ||||||
|              Pdfops.Op_Tf (fontname, scalex); |  | ||||||
|              Pdfops.Op_Tj "DEMO"; |  | ||||||
|              Pdfops.Op_ET; |  | ||||||
|              Pdfops.Op_EMC] |  | ||||||
|           in |  | ||||||
|             {(Pdfpage.blankpage Pdfpaper.a4) with |  | ||||||
|                 Pdfpage.mediabox = page.Pdfpage.mediabox; |  | ||||||
|                 Pdfpage.content = [Pdfops.stream_of_ops ops]; |  | ||||||
|                 Pdfpage.resources = |  | ||||||
|                   Pdf.Dictionary |  | ||||||
|                     [("/Font", Pdf.Dictionary [(fontname, font)]); |  | ||||||
|                      ("/ExtGState", Pdf.Dictionary |  | ||||||
|                         ["/gs0", |  | ||||||
|                         Pdf.Dictionary["/Type", Pdf.Name "/ExtGState"; "/ca", Pdf.Real 0.2]]); |  | ||||||
|                     ] |  | ||||||
|             } |  | ||||||
|         in |  | ||||||
|           do_stamp false false (BottomLeft 0.) false false false true pdf page' page (Pdf.empty ()) |  | ||||||
|  |  | ||||||
| (* \section{Set media box} *) | (* \section{Set media box} *) | ||||||
| let set_mediabox xywhlist pdf range = | let set_mediabox xywhlist pdf range = | ||||||
|   let crop_page pnum page = |   let crop_page pnum page = | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								cpdf.mli
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								cpdf.mli
									
									
									
									
									
								
							| @@ -354,9 +354,6 @@ val remove_all_text : int list -> Pdf.t -> Pdf.t | |||||||
|  |  | ||||||
| val process_xobjects : Pdf.t -> Pdfpage.t -> (Pdf.t -> Pdf.pdfobject -> Pdf.pdfobject list -> Pdf.pdfobject list) -> unit | val process_xobjects : Pdf.t -> Pdfpage.t -> (Pdf.t -> Pdf.pdfobject -> Pdf.pdfobject list -> Pdf.pdfobject list) -> unit | ||||||
|  |  | ||||||
| (** Nobble a page, given pdf, pagenumber and page *) |  | ||||||
| val nobble_page : Pdf.t -> 'a -> Pdfpage.t -> Pdfpage.t |  | ||||||
|  |  | ||||||
| val find_cpdflin : string option -> string | val find_cpdflin : string option -> string | ||||||
|  |  | ||||||
| val call_cpdflin : string -> string -> string -> string -> int | val call_cpdflin : string -> string -> string -> string -> int | ||||||
|   | |||||||
| @@ -1,5 +1,4 @@ | |||||||
| (* cpdf command line tools *) | (* cpdf command line tools *) | ||||||
| let demo = false |  | ||||||
| let noncomp = false | let noncomp = false | ||||||
| let major_version = 2 | let major_version = 2 | ||||||
| let minor_version = 5 | let minor_version = 5 | ||||||
| @@ -780,10 +779,6 @@ let rec decrypt_if_necessary (_, _, user_pw, owner_pw, was_dec_with_owner, _) op | |||||||
| (* Duplicated from cpdf.ml -> fix *) | (* Duplicated from cpdf.ml -> fix *) | ||||||
| let ppstub f n p = (f n p, n, Pdftransform.i_matrix) | let ppstub f n p = (f n p, n, Pdftransform.i_matrix) | ||||||
|  |  | ||||||
| let nobble pdf = |  | ||||||
|   if not demo then pdf else |  | ||||||
|     Cpdf.process_pages (ppstub (Cpdf.nobble_page pdf)) pdf (ilist 1 (Pdfpage.endpage pdf)) |  | ||||||
|  |  | ||||||
| (* Output Page Count *) | (* Output Page Count *) | ||||||
| let output_page_count pdf = | let output_page_count pdf = | ||||||
|   Printf.printf "%i\n" (Pdfpage.endpage pdf) |   Printf.printf "%i\n" (Pdfpage.endpage pdf) | ||||||
| @@ -2598,14 +2593,13 @@ let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf = | |||||||
|     | File outname -> |     | File outname -> | ||||||
|         begin match encryption with |         begin match encryption with | ||||||
|           None -> |           None -> | ||||||
|             let pdf = nobble pdf in |             if not is_decompress then | ||||||
|               if not is_decompress then |               begin | ||||||
|                 begin |                 ignore (Cpdf.recompress_pdf pdf); | ||||||
|                   ignore (Cpdf.recompress_pdf pdf); |                 if args.squeeze then Cpdf.squeeze ~pagedata:args.squeeze_pagedata ~recompress:args.squeeze_recompress ?logto:!logto pdf; | ||||||
|                   if args.squeeze then Cpdf.squeeze ~pagedata:args.squeeze_pagedata ~recompress:args.squeeze_recompress ?logto:!logto pdf; |               end; | ||||||
|                 end; |             Pdf.remove_unreferenced pdf; | ||||||
|               Pdf.remove_unreferenced pdf; |             really_write_pdf ~is_decompress mk_id pdf outname | ||||||
|               really_write_pdf ~is_decompress mk_id pdf outname |  | ||||||
|         | Some _ -> |         | Some _ -> | ||||||
|             really_write_pdf ~encryption ~is_decompress mk_id pdf outname |             really_write_pdf ~encryption ~is_decompress mk_id pdf outname | ||||||
|         end |         end | ||||||
| @@ -2614,14 +2608,13 @@ let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf = | |||||||
|         let temp = Filename.temp_file "cpdfstdout" ".pdf" in |         let temp = Filename.temp_file "cpdfstdout" ".pdf" in | ||||||
|           begin match encryption with |           begin match encryption with | ||||||
|             None ->  |             None ->  | ||||||
|               let pdf = nobble pdf in |               if not is_decompress then | ||||||
|                 if not is_decompress then |                 begin | ||||||
|                   begin |                   ignore (Cpdf.recompress_pdf pdf); | ||||||
|                     ignore (Cpdf.recompress_pdf pdf); |                   if args.squeeze then Cpdf.squeeze ~pagedata:args.squeeze_pagedata ~recompress:args.squeeze_recompress ?logto:!logto pdf; | ||||||
|                     if args.squeeze then Cpdf.squeeze ~pagedata:args.squeeze_pagedata ~recompress:args.squeeze_recompress ?logto:!logto pdf; |                   Pdf.remove_unreferenced pdf | ||||||
|                     Pdf.remove_unreferenced pdf |                 end; | ||||||
|                   end; |                 really_write_pdf ~encryption ~is_decompress mk_id pdf temp; | ||||||
|                   really_write_pdf ~encryption ~is_decompress mk_id pdf temp; |  | ||||||
|           | Some _ -> |           | Some _ -> | ||||||
|               really_write_pdf ~encryption ~is_decompress mk_id pdf temp |               really_write_pdf ~encryption ~is_decompress mk_id pdf temp | ||||||
|           end; |           end; | ||||||
| @@ -2727,12 +2720,12 @@ let stem s = | |||||||
|         (neq '.') (rev (explode (Filename.basename s)))))) |         (neq '.') (rev (explode (Filename.basename s)))))) | ||||||
|  |  | ||||||
| let fast_write_split_pdfs | let fast_write_split_pdfs | ||||||
|   enc splitlevel original_filename sq nobble spec main_pdf pagenums pdf_pages |   enc splitlevel original_filename sq spec main_pdf pagenums pdf_pages | ||||||
| = | = | ||||||
|   let marks = Pdfmarks.read_bookmarks main_pdf in |   let marks = Pdfmarks.read_bookmarks main_pdf in | ||||||
|     iter2 |     iter2 | ||||||
|       (fun number pagenums -> |       (fun number pagenums -> | ||||||
|          let pdf = nobble (Pdfpage.pdf_of_pages main_pdf pagenums) in |          let pdf = Pdfpage.pdf_of_pages main_pdf pagenums in | ||||||
|            let startpage, endpage = extremes pagenums in |            let startpage, endpage = extremes pagenums in | ||||||
|              let name = |              let name = | ||||||
|                name_of_spec |                name_of_spec | ||||||
| @@ -2758,7 +2751,7 @@ let bookmark_pages level pdf = | |||||||
|         (Pdfmarks.read_bookmarks pdf)) |         (Pdfmarks.read_bookmarks pdf)) | ||||||
|  |  | ||||||
| let split_at_bookmarks | let split_at_bookmarks | ||||||
|   enc original_filename ~squeeze nobble level spec pdf |   enc original_filename ~squeeze level spec pdf | ||||||
| = | = | ||||||
|   let pdf_pages = Pdfpage.pages_of_pagetree pdf in |   let pdf_pages = Pdfpage.pages_of_pagetree pdf in | ||||||
|     let points = bookmark_pages level pdf in |     let points = bookmark_pages level pdf in | ||||||
| @@ -2767,16 +2760,16 @@ let split_at_bookmarks | |||||||
|       in |       in | ||||||
|         let pts = splitat points (indx pdf_pages) in |         let pts = splitat points (indx pdf_pages) in | ||||||
|           fast_write_split_pdfs |           fast_write_split_pdfs | ||||||
|             enc level original_filename squeeze nobble spec pdf pts pdf_pages |             enc level original_filename squeeze spec pdf pts pdf_pages | ||||||
|  |  | ||||||
| let split_pdf | let split_pdf | ||||||
|   enc original_filename |   enc original_filename | ||||||
|   chunksize linearize ~cpdflin ~preserve_objstm ~create_objstm ~squeeze |   chunksize linearize ~cpdflin ~preserve_objstm ~create_objstm ~squeeze | ||||||
|   nobble spec pdf |   spec pdf | ||||||
| = | = | ||||||
|   let pdf_pages = Pdfpage.pages_of_pagetree pdf in |   let pdf_pages = Pdfpage.pages_of_pagetree pdf in | ||||||
|     fast_write_split_pdfs |     fast_write_split_pdfs | ||||||
|       enc 0 original_filename squeeze nobble spec pdf |       enc 0 original_filename squeeze spec pdf | ||||||
|       (splitinto chunksize (indx pdf_pages)) pdf_pages |       (splitinto chunksize (indx pdf_pages)) pdf_pages | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -3867,7 +3860,7 @@ let go () = | |||||||
|                 split_pdf |                 split_pdf | ||||||
|                   enc args.original_filename args.chunksize args.linearize ~cpdflin:args.cpdflin |                   enc args.original_filename args.chunksize args.linearize ~cpdflin:args.cpdflin | ||||||
|                   ~preserve_objstm:args.preserve_objstm ~create_objstm:args.preserve_objstm (*yes--always create if preserving *) |                   ~preserve_objstm:args.preserve_objstm ~create_objstm:args.preserve_objstm (*yes--always create if preserving *) | ||||||
|                   ~squeeze:args.squeeze nobble output_spec pdf |                   ~squeeze:args.squeeze output_spec pdf | ||||||
|         | _, Stdout -> error "Can't split to standard output" |         | _, Stdout -> error "Can't split to standard output" | ||||||
|         | _, NoOutputSpecified -> error "Split: No output format specified" |         | _, NoOutputSpecified -> error "Split: No output format specified" | ||||||
|         | _ -> error "Split: bad parameters" |         | _ -> error "Split: bad parameters" | ||||||
| @@ -3895,7 +3888,7 @@ let go () = | |||||||
|               in |               in | ||||||
|                 args.create_objstm <- args.preserve_objstm; |                 args.create_objstm <- args.preserve_objstm; | ||||||
|                 split_at_bookmarks |                 split_at_bookmarks | ||||||
|                   enc args.original_filename ~squeeze:args.squeeze nobble level output_spec pdf |                   enc args.original_filename ~squeeze:args.squeeze level output_spec pdf | ||||||
|         | Stdout -> error "Can't split to standard output" |         | Stdout -> error "Can't split to standard output" | ||||||
|         | NoOutputSpecified -> error "Split: No output format specified" |         | NoOutputSpecified -> error "Split: No output format specified" | ||||||
|       end |       end | ||||||
| @@ -4151,7 +4144,7 @@ let go () = | |||||||
|         (Cpdf.combine_pages args.fast (get_single_pdf args.op false) (pdfread_pdf_of_file None None over) false false true) |         (Cpdf.combine_pages args.fast (get_single_pdf args.op false) (pdfread_pdf_of_file None None over) false false true) | ||||||
|   | Some Encrypt -> |   | Some Encrypt -> | ||||||
|       let pdf = get_single_pdf args.op false in |       let pdf = get_single_pdf args.op false in | ||||||
|         let pdf = Cpdf.recompress_pdf <| nobble pdf |         let pdf = Cpdf.recompress_pdf pdf | ||||||
|         and encryption = |         and encryption = | ||||||
|           {Pdfwrite.encryption_method = |           {Pdfwrite.encryption_method = | ||||||
|              (match args.crypt_method with |              (match args.crypt_method with | ||||||
| @@ -4384,8 +4377,6 @@ let go_withargv argv = | |||||||
|     exit 0 |     exit 0 | ||||||
|   | _ ->  |   | _ ->  | ||||||
|   Hashtbl.clear filenames; |   Hashtbl.clear filenames; | ||||||
|   if demo then |  | ||||||
|     flprint "This demo is for evaluation only. http://www.coherentpdf.com/\n"; |  | ||||||
|   if noncomp then |   if noncomp then | ||||||
|     begin |     begin | ||||||
|       prerr_string "For non-commercial use only\n"; |       prerr_string "For non-commercial use only\n"; | ||||||
|   | |||||||
| @@ -7,6 +7,4 @@ val go : unit -> unit | |||||||
| val go_withargv : string array -> unit | val go_withargv : string array -> unit | ||||||
|  |  | ||||||
| (**/**) | (**/**) | ||||||
| val demo : bool |  | ||||||
|  |  | ||||||
| exception StayOnError | exception StayOnError | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user