Page 18 of 32
Re: PurePDF Version 2.0
Posted: Thu Jun 07, 2012 12:56 pm
by Olby
Hi, What is the best way to "wrap" an image in PDF. I have multiple image files I need to convert to PDFs but I don't seem to find a way to specify page width and height. My images are of various dimensions and A4 or Letter size page is not suitable in this case. Thanks.
Re: PurePDF Version 2.0
Posted: Thu Jun 07, 2012 1:09 pm
by IdeasVacuum
...There is actually a huge list of page formats to choose from, so you may find that's enough:
#PDF_PAGE_FORMAT_4A0
#PDF_PAGE_FORMAT_2A0
#PDF_PAGE_FORMAT_A0
#PDF_PAGE_FORMAT_A1
#PDF_PAGE_FORMAT_A2
#PDF_PAGE_FORMAT_A3
#PDF_PAGE_FORMAT_A4
#PDF_PAGE_FORMAT_A5
#PDF_PAGE_FORMAT_A6
#PDF_PAGE_FORMAT_A7
#PDF_PAGE_FORMAT_A8
#PDF_PAGE_FORMAT_A9
#PDF_PAGE_FORMAT_A10
#PDF_PAGE_FORMAT_B0
#PDF_PAGE_FORMAT_B1
#PDF_PAGE_FORMAT_B2
#PDF_PAGE_FORMAT_B3
#PDF_PAGE_FORMAT_B4
#PDF_PAGE_FORMAT_B5
#PDF_PAGE_FORMAT_B6
#PDF_PAGE_FORMAT_B7
#PDF_PAGE_FORMAT_B8
#PDF_PAGE_FORMAT_B9
#PDF_PAGE_FORMAT_B10
#PDF_PAGE_FORMAT_C0
#PDF_PAGE_FORMAT_C1
#PDF_PAGE_FORMAT_C2
#PDF_PAGE_FORMAT_C3
#PDF_PAGE_FORMAT_C4
#PDF_PAGE_FORMAT_C5
#PDF_PAGE_FORMAT_C6
#PDF_PAGE_FORMAT_C7
#PDF_PAGE_FORMAT_C8
#PDF_PAGE_FORMAT_C9
#PDF_PAGE_FORMAT_C10
#PDF_PAGE_FORMAT_RA0
#PDF_PAGE_FORMAT_RA1
#PDF_PAGE_FORMAT_RA2
#PDF_PAGE_FORMAT_RA3
#PDF_PAGE_FORMAT_RA4
#PDF_PAGE_FORMAT_SRA0
#PDF_PAGE_FORMAT_SRA1
#PDF_PAGE_FORMAT_SRA2
#PDF_PAGE_FORMAT_SRA3
#PDF_PAGE_FORMAT_SRA4
#PDF_PAGE_FORMAT_LETTER
#PDF_PAGE_FORMAT_LEGAL
#PDF_PAGE_FORMAT_EXECUTIVE
#PDF_PAGE_FORMAT_FOLIO
Re: PurePDF Version 2.0
Posted: Thu Jun 07, 2012 1:38 pm
by Olby
I have an image that has dimensions of 1714x1800. Which page mode should I choose then (it needs to done automatically)? We also have some US cheques scans. Obviously there should be some kind of command to set exact page dimensions. Think I used a library called HaruPDF and I believe it did have such command. Thanks.
Oh and by the way I cant leave white-space around the images, page size should match image size pixel to pixel (libtiff does this).
Re: PurePDF Version 2.0
Posted: Thu Jun 07, 2012 3:36 pm
by IdeasVacuum
OK, try this:
Code: Select all
#PDF_PAGE_FORMAT_CUSTOM = "1714.00,1800.00"
sPdfName.s = "C:\TestCustomFormat.pdf"
sImageFile.s = "C:\TestCustomFormat.png"
pdf_Create("P","mm",#PDF_PAGE_FORMAT_CUSTOM)
pdf_SetMargins(0.00,0.00,0.00)
pdf_SetFillColor(230,230,230) ;Light Gray
pdf_AddPage()
pdf_Image(sImageFile,0,0,1800)
pdf_Save(sPdfName)
;View PDF created
RunProgram(sPdfName)
That's not an official constant but it seems to work. Note though that Adobe Reader for one does not like zero margins, so you may have to accept a tiny margin.
Re: PurePDF Version 2.0
Posted: Thu Jun 07, 2012 9:14 pm
by Olby
Vacuum, thanks for your code snippet, but unfortunately I only get like quarter of an image saved as PDF. Feels like it has higher DPI resolution than the page and gets truncated. 200 dpi btw. Any ideas how to fix that? Thanks.
Re: PurePDF Version 2.0
Posted: Thu Jun 07, 2012 11:10 pm
by IdeasVacuum
Not sure. I think PDF perhaps is using a 'printing' dpi?
For example, #PDF_PAGE_FORMAT_A4 = 595.28,841.89
On screen, an A4 sheet is 794 x 1123 pix @ 96dpi (210 x 297mm)
Edit: Tried a 96dpi A4 image and a 200dpi A4 image. Both verify in Adobe reader as A4 (210 x 297mm).
The image is a simple 10 x 10 grid.
PDF of 96dpi image: The top left-hand corner of the image fills the whole page.
PDF of 200dpi image: None of the grid can be seen.
Code: Select all
; sPdfName.s = "C:\TestA4Format96dpi.pdf"
;sImageFile.s = "C:\TestA4Format96dpi.png"
sPdfName.s = "C:\TestA4Format200dpi.pdf"
sImageFile.s = "TestA4Format200dpi.png"
pdf_Create("P","mm",#PDF_PAGE_FORMAT_A4) ;210x297mm; 794x1123pix
pdf_SetMargins(0.00,0.00,0.00)
pdf_SetFillColor(230,230,230) ;Light Gray
pdf_AddPage()
pdf_Image(sImageFile,0,0,1123)
pdf_Save(sPdfName)
;View PDF created
RunProgram(sPdfName)
Link to files:
TestA4FormatPDF.rar
Re: PurePDF Version 2.0
Posted: Fri Jun 08, 2012 1:20 pm
by Olby
This is exactly what I'm getting with my own image. Even if width and height is specified for pdf_image only top left corner is visible in the produced file.

Re: PurePDF Version 2.0
Posted: Fri Jun 08, 2012 3:24 pm
by IdeasVacuum
Doh! I have the pdf_Image function wrongly primed. - firstly, the last value is width not height and secondly it should be in pdf document units, in this case mm!
So:
works fine for the 96dpi image. 200dpi image still fails.
Going back to custome size, @96dpi, the whole image is displayed in the PDF file, but the page size is wrong:
Code: Select all
#PDF_PAGE_FORMAT_CUSTOM = "1714.00,1800.00" ;453.50 x 476.25mm or 17.85 x 18.75in
sPdfName.s = "C:\TestCustomFormat.pdf"
sImageFile.s = "C:\TestCustomFormat.png"
pdf_Create("P","mm",#PDF_PAGE_FORMAT_CUSTOM) ;453.50 x 476.25mm; 1714 x 1800pix
pdf_SetMargins(0.00,0.00,0.00)
pdf_SetFillColor(230,230,230) ;Light Gray
pdf_AddPage()
pdf_Image(sImageFile,0,0,453.5)
pdf_Save(sPdfName)
;View PDF created
RunProgram(sPdfName)
;resulting PDF page size is 604.70 x 635.00mm
What we are trying to do, in Adobe jargon, is to define a 'Postscript Custom Page Size'.
I think that maybe the lib is selecting the nearest size that fits? Maybe not. Hopefully ABBKlaus can put us out of our misery

Re: PurePDF Version 2.0
Posted: Sat Jun 09, 2012 3:57 pm
by Thorsten1867
Is it possible to add encryption (AES) with a password to open the PDF to PurePDF? (Adobe PDF Reference => Syntax - Encryption)
Re: PurePDF Version 2.0
Posted: Sat Jun 09, 2012 7:22 pm
by ABBKlaus
@olby, have you tried using point in PDF_Create() ?
Code: Select all
#PDF_PAGE_FORMAT_CUSTOM="1024,768"
Define sPdfName.s = "C:\TestCustomFormat.pdf"
Define sImageFile.s = "c:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg"
pdf_Create("P","pt",#PDF_PAGE_FORMAT_CUSTOM)
pdf_SetMargins(0,0,0)
pdf_SetFillColor(230,230,230) ;Light Gray
pdf_AddPage()
pdf_Image(sImageFile,0,0,1024)
pdf_Save(sPdfName)
;View PDF created
RunProgram(sPdfName)
@Thorsten1867, atm no. I think it was removed because of the redesign of PurePDF. It was using RC4 if i remember correctly

Re: PurePDF Version 2.0
Posted: Sat Jun 09, 2012 9:24 pm
by Olby
Spiffy! It works, thanks very much Klaus.
Re: PurePDF Version 2.0
Posted: Sat Jun 09, 2012 9:33 pm
by ABBKlaus
Glad i could help
Does it really worked without the missing #PDF_PAGE_FORMAT_CUSTOM ?
Re: PurePDF Version 2.0
Posted: Sat Jun 09, 2012 10:30 pm
by IdeasVacuum
Strange, not working on my machine (PB4.61, WinXP 32) with the custom sized image:
Code: Select all
#PDF_PAGE_FORMAT_CUSTOM="1714.00,1800.00"
Define sPdfName.s = "C:\TestCustomFormat.pdf"
Define sImageFile.s = "TestCustomFormat.png"
pdf_Create("P","pt",#PDF_PAGE_FORMAT_CUSTOM)
pdf_SetMargins(0,0,0)
pdf_SetFillColor(230,230,230) ;Light Gray
pdf_AddPage()
pdf_Image(sImageFile,0,0,1714)
pdf_Save(sPdfName)
;View PDF created
RunProgram(sPdfName)
PDF Result is a blank page, 604.7 x 635.0mm. The size should be 453.5 x 476.25mm
The 200dpi image also does not display:
Code: Select all
#PDF_PAGE_FORMAT_CUSTOM="794.00,1123.00"
Define sPdfName.s = "C:\TestA4Format200dpi.pdf"
Define sImageFile.s = "TestA4Format200dpi.png"
pdf_Create("P","pt",#PDF_PAGE_FORMAT_CUSTOM)
pdf_SetMargins(0,0,0)
pdf_SetFillColor(230,230,230) ;Light Gray
pdf_AddPage()
pdf_Image(sImageFile,0,0,794)
pdf_Save(sPdfName)
;View PDF created
RunProgram(sPdfName)
PDF Page is 280 x 396mm when it should be 210 x 297mm
Really confused now!

Re: PurePDF Version 2.0
Posted: Sat Jun 09, 2012 11:09 pm
by ABBKlaus
Simple mathematics
Code: Select all
ptinch.d=1/72 ; each point is ~0.014" (1/72 of an inch)
ptcm.d=(1/72)*25.4 ; each point is ~0.35 mm
Debug ptinch ; 0.013888888888888888
Debug ptcm ; 0.35277777777777775
Debug 1714 * ptcm ; 604.66111111111104
Debug 1800 * ptcm ; 634.99999999999989
Debug 794 * ptcm ; 280.10555555555555
Debug 1123 * ptcm ; 396.16944444444442
Re: PurePDF Version 2.0
Posted: Sat Jun 09, 2012 11:30 pm
by Olby
Genius!

Thanks for clarifying the metrics.