[Module] pbPDF-Module

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: [Module] pbPDF-Module

Post by blueb »

Thanks Thorsten,

I'm struggling to find out why "pbPDF-Watermark.pb" does NOT display the watermark, when I run the program.

Latest Win 10 Pro and PB 5.71 B2 (x86).

Tried 3 different PDF viewers, in case they might be the issue.

Perhaps you have an idea? :?:
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

BugFix: pbPDF-Watermark.pb
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: [Module] pbPDF-Module

Post by blueb »

Thanks Thorsten, it's appreciated. 8)
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Module] pbPDF-Module

Post by Paul »

Very nice Module.

Would you be able to give a small example of how to properly use PDF::ImageMemory with PNG image that is included in a file?
My attempts just crash on line 2284 with "MemoryID is not valid"
Image Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

I tested that.
Apparently there is only the image content in the memory and not the header.
Unfortunately it is not possible to evaluate the header and insert the image into the PDF.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Module] pbPDF-Module

Post by Paul »

Ok, so PDF::ImageMemory doesn't work :(

I then tried with PDF::Image and unfortunately that also causes problems.
If I have an image in a header and there is more that 1 page in the PDF, the PDF that is generated is corrupt.
(I can view the first page but if I scroll to the second page Adobe Reader gives error)

Try this code with an image of your choice...

Code: Select all

#PDF=1
pdf$="test.pdf"
XIncludeFile "pbPDFModule.pbi"

Procedure Header()
  PDF::Image(#PDF, "logo.jpg",5,8,30,0)
  PDF::SetFont(#PDF, "Arial","B", 16)
  PDF::SetPosY(#PDF, 10)
  PDF::SetPosX(#PDF, 35)
  PDF::Cell(#PDF, "Test Page", 100, 16)      
  PDF::Ln(#PDF, 20)       
EndProcedure


If PDF::Create(#PDF,PDF::#Landscape,"mm",PDF::#Format_Letter)
  PDF::SetPageCompression(#PDF, #True)
  PDF::SetViewerPreferences(#PDF, PDF::#FitWindow)

  PDF::SetHeaderProcedure(#PDF,@Header())
  PDF::Enableheader(#PDF, #True)  
  PDF::AddPage(#PDF)
 
  For tmp=1 To 60
    PDF::Cell(#PDF, "This is a test"+Str(tmp), 100, 5, #False)
    PDF::Ln(#PDF)                                
  Next
        
  PDF::Close(#PDF, pdf$)    
  RunProgram(pdf$)
EndIf
Image Image
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Module] pbPDF-Module

Post by Paul »

Thorsten, would you be able to take a look at this?
This module would be very useful if you could get images in the header working properly.
Image Image
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: [Module] pbPDF-Module

Post by Derren »

Wow.
This is going to be a bunch of work to learn all these new commands, but this is 100x better than trying to create a PDF from scratch.
Thanks a TON for this Module!!! :)
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

Paul wrote:I then tried with PDF::Image and unfortunately that also causes problems.
If I have an image in a header and there is more that 1 page in the PDF, the PDF that is generated is corrupt.
(I can view the first page but if I scroll to the second page Adobe Reader gives error)
It was a little complicated to find the bug, but here it is:

Code: Select all

11 0 obj
<</Length 359>>
stream
2 J
0.57 w
BT /F2 12.00 Tf ET
q 85.04 0 0 NaN 14.17 NaN cm /I1 Do Q
BT /F1 16.00 Tf ET
BT 102.05 556.18 Td (Test Page) Tj ET
BT /F2 12.00 Tf ET
BT 31.18 516.27 Td (This is a test1) Tj ET
endstream
endobj
Bugfix: PDF::Image()
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
hoerbie
Enthusiast
Enthusiast
Posts: 119
Joined: Fri Dec 06, 2013 11:57 am
Location: DE/BY/MUC

Re: [Module] pbPDF-Module

Post by hoerbie »

Thanks a lot for this module.

I found two small bugs in update from 11.11.2019:

[COMPILER] Zeile 572: Constant already declared with a different value: #Version.
->#Version is declared in line 190 and again in 572, PB doesn't like this

Line 393: #Format_SRA0 = "2551.18,3628.35)"
->There is a ) where I think it shouldn't be
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

Fixed
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Oliver13
User
User
Posts: 82
Joined: Thu Sep 30, 2010 6:40 am

Re: [Module] pbPDF-Module

Post by Oliver13 »

I found another bug: if you encypt the PDF, images do not appear in PDF
To reproduce, please use the modified sample code below:

TX, Oliver

Code: Select all

XIncludeFile "..\pbPDFModule.pbi"

Define LinkID.i, File$ = "pbPDF-Images.pdf"

#PDF = 1

If PDF::Create(#PDF)
 
  PDF::AddPage(#PDF)
 
  LinkID = PDF::AddLinkURL(#PDF, "https://www.purebasic.com/")
 
  PDF::Image(#PDF, "PureBasic.png", 10,  10, 30, 0, LinkID)
  PDF::Image(#PDF, "PureBasic.jpg", 10, 110, 60, 0, LinkID)
  PDF::Image(#PDF, "PureBasic.jp2", 10, 210, 80, 0, LinkID)
  PDF::SetEncryption(#PDF,"test1","test",#False) ; if removed, images do appear
  PDF::Close(#PDF, File$)
EndIf

RunProgram(File$)
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

@Thorsten1867, I wish you would share the secret in how you find time to work in all your great modules.

@Oliver13 [edit] Encryption might work,
I just figured it didn't since there was an error on a single line of text PDF which I encrypted,
but it turns out you get an error on non-encrypted PDFs: "invalid xref table"

The URL links for images cannot be reused so once you attach "LinkID" to the first image, the link is gone.
You can create the URL link and add it at the same time:

Code: Select all

XIncludeFile "..\pbPDFModule.pbi"

Define LinkID.i, LinkURL.i, File$ = "pbPDF-Images.pdf"

#PDF = 1

If PDF::Create(#PDF)
 
  PDF::AddPage(#PDF)
 
  LinkURL =  "https://www.purebasic.com/"
  LinkID = PDF::AddLinkURL(#PDF, "https://www.purebasic.com/")
 
  PDF::Image(#PDF, "purebasic.png", 10,  10, 30, 0, LinkID)
  PDF::Image(#PDF, "PureBasic.jpg", 10, 110, 60, 0, PDF::AddLinkURL(#PDF, LinkURL))
  PDF::Image(#PDF, "PureBasic.jp2", 10, 210, 80, 0, PDF::AddLinkURL(#PDF, LinkURL))
  PDF::EmbedFont(#PDF, "l_10646.ttf", "LucidaSans", "", PDF::#Unicode)
  PDF::SetFont(#PDF, "LucidaSans", "", 14)
  PDF::PlaceText(#PDF, "This is an embedded Unicode-font (LucidaSans)", 20, 50)
;  PDF::SetEncryption(#PDF,"test1","test",#False) ; if removed, images do appear
  PDF::Close(#PDF, File$)
EndIf

RunProgram(File$)
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Oliver13
User
User
Posts: 82
Joined: Thu Sep 30, 2010 6:40 am

Re: [Module] pbPDF-Module

Post by Oliver13 »

normeus wrote:Encryption might work,
I just figured it didn't since there was an error on a single line of text PDF which I encrypted,
but it turns out you get an error on non-encrypted PDFs: "invalid xref table"

The URL links for images cannot be reused so once you attach "LinkID" to the first image, the link is gone.
Hi Norm., thank you, but regrettably this does not help either. Even if you remove all of the links, the images will not appear in the encrypted PDF.

Code: Select all

XIncludeFile "..\pbPDFModule.pbi"

Define LinkID.i, File$ = "pbPDF-Images.pdf"

#PDF = 1

If PDF::Create(#PDF)
  
  PDF::AddPage(#PDF)
  
 ; LinkID = PDF::AddLinkURL(#PDF, "https://www.purebasic.com/")
  
  PDF::Image(#PDF, "PureBasic.png", 10,  10, 30, 0)
  PDF::Image(#PDF, "PureBasic.jpg", 10, 110, 60, 0)
  PDF::Image(#PDF, "PureBasic.jp2", 10, 210, 80, 0)
  PDF::SetEncryption(#PDF,"test","test",#False) 
  
  PDF::Close(#PDF, File$)
EndIf

RunProgram(File$) ;- PDF is encrypted, but does not show images

Oliver
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

Oliver,
sorry my post was confusing, I just pointed out how "AddLinkURL" currently works.
nothing to do with the encryption problem.

for the encryption problem, it turns out that images are not being encrypted.
@Thorsten1867 probably just forgot to add a "#objMemory" test somewhere to encrypt images.
The PDF reader tries to change the Image which needs no changing and images don't display.



Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Post Reply