[Module] PurePDF

Share your advanced PureBasic knowledge/code with the community.
Wolfgang2
User
User
Posts: 11
Joined: Wed Jan 31, 2018 4:03 pm

Re: [Module] PurePDF

Post by Wolfgang2 »

Dear normeus,

I do know and understand all this.
My question is regarding the opposite behaviour: I do not want to have two references to the same embedded file in the "Attachments" sidebar.

I observed that if you add a file annotation ( pdf_SetAFile() ) with the method from the Tutorial29, the embedded file shows up twice in the PDF.
To see that effect:
- Run Tutorial29
- In Acrobat Reader, on the left side, open the sidebar for "Attachments".
- See the same file showing up twice. Usually ( but not always ) you can click-open just one of the two.

I did look at the created PDF file today and it seems that the embedded file is just embedded once, indeed.
But it does show up twice in the "Attachments" sidebar in Acrobat Reader.
I do not understand PDF format and in the text edit, it was a mixture of text and binary. But it seems the issue is that PurePDF creates two references to the embedded file if you use pdf_SetAFile this way. Obviously it must create a reference when you pdf_EmbedFile() . But then it seems to create a 2nd one when you create the file annotation.

So, this may be called a bug.
I had a quick look in the PurePDF sources, but they are too big to understand without any documentation in a short time.

Thank you,
Wolfgang
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] PurePDF

Post by normeus »

Wolfgang2,

If you want to attach a file use the command to attach a file:

Code: Select all

pdf_EmbedFile("filename","description of this file if you like")
You don't need anything else. The rest of example 29 shows how to create an Annotation which points to the internal file.
The side effect is that you see 2 pointers to the attachment.
1 from Annotation and 2nd one from Attachment.
I use annotations because the people that use my pdfs do not know how to look at attachments tab so I have to create a "click on this link Annotation."
They will never know there are two links.
Both of the links should work the same. if they don't you might have a setting in your pdf reader that prevents opening attachments or annotations with attachments.
For more info about Attachments see:
http://www.purebasic.fr/english/viewtop ... 03#p517703

Thank you.
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Wolfgang2
User
User
Posts: 11
Joined: Wed Jan 31, 2018 4:03 pm

Re: [Module] PurePDF

Post by Wolfgang2 »

normeus, thanks for the explenation and sorry for the long delay of my reply.
So, this is a feature. All OK.

Thank you,
Wolfgang2
Wolfgang2
User
User
Posts: 11
Joined: Wed Jan 31, 2018 4:03 pm

Re: [Module] PurePDF

Post by Wolfgang2 »

normeus, I have another issue with purePDF:

Embedding fonts that are on windows system as "TrueType collection font file" ( .ttc ) crashes purePDF.
I need to create chinese PDF files that need to be readable on any PC, so font needs to be embedded.
As I cannot guarantee which fonts are available on the PC that runs my program, I had the idea to let the user choose a font in the program setup.
Now, the issue is that there is no way to see if a font is regular truetype ( .ttf) or the above mentioned TrueType font collection ( .ttc)
I am also not awary of any way to check this within the PB code.

The fact that trying to embedd a .ttc font crashes the program with an memory access error makes this a pretty bad issue.

Excample code:

Code: Select all

XIncludeFile "PurePdfModule.pbi"
Global title.s = "PDF font embedding test"

PDF::Create()
PDF::AddPage()

PDF::SetFont("SimSun","",12)
PDF::Text(10,10,"这是一个嵌入式字体(SimSun Size 12)")

Define file$="purePDF_EmbedFonts.pdf"

PDF::Save(file$)
RunProgram(file$)
This does crash the program with a memory access error in line 1230 of PurePdfModule:

Code: Select all

formatID     = ipdf_EndianW(*subtable\format)

Code: Select all

[14:01:08] Waiting for executable to start...
[14:01:08] Executable type: Windows - x64  (64bit, Unicode)
[14:01:08] Executable started.
[14:01:08] [ERROR] PurePdfModule.pbi (Line: 1230)
[14:01:08] [ERROR] Invalid memory access. (read error at address 178311806)
The same code with "SimHei" Font ( .ttf) does work as expected.

Unfortunately I am not good enough in either, PB or PDF, to fix that issue on my own.

So, any hint where to look at / what to do is very appreciated.
Thank you,
Wolfgang2
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: [Module] PurePDF

Post by morosh »

Hello:
Seems not working with unicode strings:

Code: Select all

XIncludeFile "E:\install\dvd1\dev_soft\purebasic\extra\PurePdfModule\PurePdfModule.pbi"
;XIncludeFile "PurePdfModule.pbi"

;Unicode example
;===============


Define File$

File$=GetFilePart(#PB_Compiler_File)
File$=Mid(File$,1,Len(File$)-Len(GetExtensionPart(File$))-1)

PDF::Create()
PDF::AddPage()
PDF::SetFont("Arial","",28)
PDF::Text(20,30,"Hello السلام عليكم")

PDF::Save(File$+".pdf")
RunProgram(File$+".pdf")
any tips?

thanks
PureBasic: Surprisingly simple, diabolically powerful
PhilGeorges
New User
New User
Posts: 6
Joined: Wed Nov 09, 2016 9:55 am
Location: Dijon, France

Re: [Module] PurePDF

Post by PhilGeorges »

Thank you, my problem (specific font on Mac Osx) is now fixed. PDF file is now perfect !

Very Good work, useful !
Philippe GEORGES F1HSB
Amateur Radio Station VHF-UHF
f1hsb@sfr.fr
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] PurePDF

Post by Thorsten1867 »

'PurePDF' has been replaced by 'pbPDFModule.pbi'
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: [Module] PurePDF

Post by collectordave »

Trying to display € in PDF using code below:-

Code: Select all

IncludeFile "pbPDFModule.pbi"

PDF::Create(0)
PDF::AddPage(0)
PDF::SetFont(0, "Arial", "B", 16)
PDF::Cell(0, StrF(PDF::GetPageWidth(0), 0) + "x" + StrF(PDF::GetPageHeight(0), 0) + "€m€m€", 40, 10, #True)

PDF::Save(0,"Testing.PDF")
    
RunProgram("Open" ,Chr(34) + "Testing.PDF" + Chr(34),"")
Running on my MAC the € sign does not appear at all.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: [Module] PurePDF

Post by collectordave »

A little more info

Changed € to char(128) and it shows a euro symbol in the pdf.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

Re: [Module] PurePDF

Post by skinkairewalker »

have a way to import other pdf and edit it ?
Post Reply