Page 1 of 1

pdf file

Posted: Sat Jan 04, 2025 3:29 pm
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é.

Re: pdf file

Posted: Sat Jan 04, 2025 3:42 pm
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


Re: pdf file

Posted: Sat Jan 04, 2025 7:05 pm
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

Re: pdf file

Posted: Sun Jan 05, 2025 9:48 am
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: