pdf file

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

pdf file

Post by jak64 »

Good morning,
Is it possible to create a pdf document in PureBasic?

I found this code but it generates an error! I am with Purebasic v6.12 on Windows 11

Thanks to you

Code: Select all

  If StartVectorDrawing(PdfVectorOutput("test.pdf", 595, 842))  
    VectorFont(FontID(0), 25)
    
    MovePathCursor(20, 20)
    DrawVectorText("This is page 1...")
    
    NewVectorPage()
    
    MovePathCursor(20, 20)
    DrawVectorText("This is page 2...")      

    StopVectorDrawing()
  EndIf
error :
[15 :21 :36] [COMPILER] Ligne 15: Erreur de syntaxe.
[15 :21 :44] Attente du démarrage du programme...
[15 :21 :43] Type d'exécutable: Windows - x64 (64bit, Unicode)
[15 :21 :44] Exécutable démarré.
[15 :21 :44] [ERREUR] Ligne: 3
[15 :21 :44] [ERREUR] StartVectorDrawing(): L'argument 'Output' spécifié n'est pas valide.
[15 :21 :50] Le programme a été arrêté.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: pdf file

Post by mk-soft »

Please always put running code in.

Test whether the pdf output file can also be created.

Code: Select all

LoadFont(0, "Times New Roman", 20)

pdf_out = PdfVectorOutput(GetUserDirectory(#PB_Directory_Downloads) + "test.pdf", 595, 842)
If pdf_out
  If StartVectorDrawing(pdf_out)
    VectorFont(FontID(0), 25)
    
    MovePathCursor(20, 20)
    DrawVectorText("This is page 1...")
    
    NewVectorPage()
    
    MovePathCursor(20, 20)
    DrawVectorText("This is page 2...")      
    
    StopVectorDrawing()
  EndIf
Else
  Debug "Error: Create pdf file"
EndIf

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: pdf file

Post by jak64 »

Hello mk-soft,
I tested the code and it works.
For information, the pdf document was created in the “Downloads” folder

Thank you for your help
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: pdf file

Post by Marc56us »

It's a classic mistake not to put a complete path in a file you've created. The result is that if you don't name the file, it will try to write to the PB directory program, which by default is ProgramFile and to which the standard user is not allowed to write.

Alway uses GetUserDirectory() or GetTemporaryDirectory() + filename

A remark could be added in the help section, given the number of times users forget this.

:wink:
Post Reply