[Module] pbPDF-Module

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 223
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: [Module] pbPDF-Module

Post by DeanH »

It could be the viewer. I'm using Foxit.
Little_man
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: [Module] pbPDF-Module

Post by Little_man »

Is there a solution for "unicode"?
Example: "Styczeń" (Polish) is displayed as "SryczeD".

Kind regards,
Little_man
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: [Module] pbPDF-Module

Post by loulou2522 »

Little_man wrote: Tue Jan 04, 2022 7:55 am Is there a solution for "unicode"?
Example: "Styczeń" (Polish) is displayed as "SryczeD".

Kind regards,
Little_man
Maybe you have to load a police which allow this kind of character
l1marik
User
User
Posts: 49
Joined: Tue Jun 30, 2020 6:22 am

Re: [Module] pbPDF-Module

Post by l1marik »

Did you found solution?
Little_man wrote: Tue Jan 04, 2022 7:55 am Is there a solution for "unicode"?
Example: "Styczeń" (Polish) is displayed as "SryczeD".

Kind regards,
Little_man
Little_man
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: [Module] pbPDF-Module

Post by Little_man »

I have not found a solution to the problem
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

This is usually related to the font you are using. For coding I use a free font which happens to also have the character you need.
For my example, first download "Fira code" font from github : https://github.com/tonsky/FiraCode
( if you have a font that contains the character you need, use that font, but you have to make sure pbPDF finds it like I am doing with the example with Fira Code or it will use the default font and you'll see a "D")

Code: Select all

XIncludeFile "..\pbPDFModule.pbi"

Define File$="pbPDF-Example_Unicode_v1.pdf"
#PDF = 1
;  Create an instance of PDF
If PDF::Create(#PDF)
    ;  Always add a page to create a PDF or you'll get an error
  ;  Page size and orientation is optional, I like to add it because you can have multiple page sizes in a PDF   
  PDF::AddPage(#PDF,PDF::#Landscape,PDF::#format_letter)
  
  ; specialty unicode font, which contains the character you need
  PDF::EMbedFont(#PDF, "C:\WINDOWS\Fonts\FIRACODE-REGULAR.TTF","FiraCode","",PDF::#Unicode)
  
    PDF::SetFont(#PDF, "FiraCode", "", 14)
  PDF::PlaceText(#PDF, "This is an embedded Unicode-font (Fira Code) Styczeń  or using chr($0144) = "+Chr($0144), 10, 50)
  
    PDF::Close(#PDF, File$)
  
EndIf

RunProgram(File$)
I hope this helps.
Norm
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Little_man
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: [Module] pbPDF-Module

Post by Little_man »

Normeus,

Thank you for the code but then I have another question; how to remove the square in front of the text.

Kind regards,
Little_man
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

Make sure you have the latest pbPDF-Module.
pbPDF-Module

Code: Select all

;/ [ PB V5.7x / All OS ]
;/
;/  © 2022 Thorsten1867 (12/2018)
;/ ( based on 'PurePDF' by LuckyLuke / ABBKlaus / normeus )
;/

; Last Update: 04.05.2022
[edit: figured out that to add images the URL has to end in an actual png or jpg file. It can not be an econded name like "Tq6cC"]
here's a link to an img with the results I don't get a square, with the sample code I posted:
Image

Norm.
Last edited by normeus on Thu Dec 22, 2022 7:41 pm, edited 1 time in total.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Little_man
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: [Module] pbPDF-Module

Post by Little_man »

Normeus,

Problem solved, there was an issue with me !!..

Kind regards,
Little_man
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

Re: [Module] pbPDF-Module

Post by skinkairewalker »

have a way to import other pdf and edit it ?
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

Infratec has some code, using PDFium.dll that might do what you need here:

viewtopic.php?p=553210#p553210

Norm
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

Re: [Module] pbPDF-Module

Post by skinkairewalker »

I would like to add text, images and etc to an existing pdf exported from an office [ word ]
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

PB ide v6.03 has a new check for invalid Chr() numbers. You get a compile error, @idle placed a request to change the error to a warning on October 16, 20023. viewtopic.php?p=609396#p609396

If you compile pbPDF-Module and you get an error Chr() out of range, alternative is to compile from the command line. If you are using English for the pdfs you create with pbPDF-Module then you can do the following change to be able to compile from IDE:

Code: Select all

;around line 5893
              For i=0 To 65535
                If i >= 55296 And i<=57343 ; skip the chraracters ide now marks as error
                Continue
                Else
                If FindMapElement(PDF()\Fonts()\CharWidth(), Chr(i))
                  objStrg + Str(i) + " [" + Str(PDF()\Fonts()\CharWidth(Chr(i))) + "] "
                EndIf
                EndIf
              Next   
It might work for other languages, but I only tried it using English.
Here is a link to @idle's UTF16 module:(it's a nice read, for people using different languages of the world in their programs)
viewtopic.php?p=592461#p592461

Thank you.
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Jan2004
Enthusiast
Enthusiast
Posts: 154
Joined: Fri Jan 07, 2005 7:17 pm

Re: [Module] pbPDF-Module

Post by Jan2004 »

Thorsten1867 thank you for a great library. I am interested in the use of Polish letters. The example provided by normeus works very well. For several days I tried to use other fonts, Windows system fonts and the Lato font. However, this did not produce the expected result. Maybe my dear colleagues will tell how to use Windows system fonts for polish letters and why the example below, based on normeus example, with Lato fonts does not work. Lato fonts can be downloaded here:
https://www.latofonts.com/lato-free-fonts/

Code: Select all

XIncludeFile "..\pbPDFModule.pbi"

Define File$="pbPDF-Example_forLato.pdf"
#PDF = 1
;  Create an instance of PDF
If PDF::Create(#PDF)
  ;  Always add a page to create a PDF or you'll get an error
  ;  Page size and orientation is optional, I like to add it because you can have multiple page sizes in a PDF   
  PDF::AddPage(#PDF,PDF::#Landscape,PDF::#format_letter)
  
  ; specialty unicode font, which contains the character you need
  PDF::EMbedFont(#PDF, "C:\WINDOWS\Fonts\Lato-Light.ttF","Lato","",PDF::#Unicode)
  
  PDF::SetFont(#PDF, "lato", "", 14)
  PDF::PlaceText(#PDF, "This is font Lato for Styczeń  or other polish letters: ŻŹĆŃŁÓĄŚĘĘ żźćńłóśąę", 10, 50)
  
  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 »

Sorry that was part of the code I added. It should give you an error with font file not found. That's the problem, the file is not there. I'll have time to look at the code later today, I hope, meantime try this:

Code: Select all

  PDF::EMbedFont(#PDF,"c:/Users/"+UserName()+"/appdata/local/microsoft/windows/fonts/LATO-BLACK.TTF","Lato","",PDF::#Unicode)
  
  PDF::SetFont(#PDF, "Lato", "", 14)
Notice that I used Lato black because Lato-Light does not show the special characters, you can also just unzip the fonts to a folder and call them for that folder.

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