PurePDF Version 2.0
Re: PurePDF Version 2.0
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.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: PurePDF Version 2.0
...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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_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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: PurePDF Version 2.0
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).
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).
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: PurePDF Version 2.0
OK, try this:
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.
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)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: PurePDF Version 2.0
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.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: PurePDF Version 2.0
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.
Link to files: TestA4FormatPDF.rar
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)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: PurePDF Version 2.0
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. 

Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: PurePDF Version 2.0
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:
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
So:
Code: Select all
pdf_Image(sImageFile,0,0,210)
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
I think that maybe the lib is selecting the nearest size that fits? Maybe not. Hopefully ABBKlaus can put us out of our misery

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- Thorsten1867
- Addict
- Posts: 1372
- Joined: Wed Aug 24, 2005 4:02 pm
- Location: Germany
Re: PurePDF Version 2.0
Is it possible to add encryption (AES) with a password to open the PDF to PurePDF? (Adobe PDF Reference => Syntax - Encryption)
Translated with http://www.DeepL.com/Translator
Download of PureBasic - Modules
Download of PureBasic - Programs
[Windows 11 x64] [PB V5.7x]
Download of PureBasic - Modules
Download of PureBasic - Programs
[Windows 11 x64] [PB V5.7x]
Re: PurePDF Version 2.0
@olby, have you tried using point in PDF_Create() ?
@Thorsten1867, atm no. I think it was removed because of the redesign of PurePDF. It was using RC4 if i remember correctly 
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)

Last edited by ABBKlaus on Sat Jun 09, 2012 9:34 pm, edited 1 time in total.
Re: PurePDF Version 2.0
Spiffy! It works, thanks very much Klaus.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
Re: PurePDF Version 2.0
Glad i could help
Does it really worked without the missing #PDF_PAGE_FORMAT_CUSTOM ?

Does it really worked without the missing #PDF_PAGE_FORMAT_CUSTOM ?
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: PurePDF Version 2.0
Strange, not working on my machine (PB4.61, WinXP 32) with the custom sized image:
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:
PDF Page is 280 x 396mm when it should be 210 x 297mm
Really confused now!
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)
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)
Really confused now!

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: PurePDF Version 2.0
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
Genius!
Thanks for clarifying the metrics.

Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)