PB.Ex PDF (Windows)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

PB.Ex PDF (Windows)

Post by RSBasic »

Hello

With this library you can create and open PDF documents. There are also other functions available, such as Password protection
Further functions will be added in the future, e.g: Watermark, separate and merge multiple PDF documents, create bookmarks, include graphics, create tables, links, form fields, annotations, include custom/foreign fonts

Functions:
  • CreatePDF()
    • Syntax:

      Code: Select all

      Result = CreatePDF(ID, @ErrorOutput$)
    • Description: Creates an empty PDF document with an empty page in memory.
    • Parameter:
      1. ID: A unique number for the document. #PB_Any can be used to generate the number automatically.
      2. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful. If #PB_Any is used, the ID is returned.
    • Example:

      Code: Select all

      EnableExplicit
      
      Global PBEx_PDF
      
      #PBEx_PDF_PageOrientation_Portrait = 0
      #PBEx_PDF_PageOrientation_Landscape = 1
      #PBEx_PDF_PageSize_A0 = 1
      #PBEx_PDF_PageSize_A1 = 2
      #PBEx_PDF_PageSize_A2 = 3
      #PBEx_PDF_PageSize_A3 = 4
      #PBEx_PDF_PageSize_A4 = 5
      #PBEx_PDF_PageSize_A5 = 6
      #PBEx_PDF_PageSize_B0 = 7
      #PBEx_PDF_PageSize_B1 = 8
      #PBEx_PDF_PageSize_B2 = 9
      #PBEx_PDF_PageSize_B3 = 10
      #PBEx_PDF_PageSize_B4 = 11
      #PBEx_PDF_PageSize_B5 = 12
      #PBEx_PDF_PageSize_RA0 = 13
      #PBEx_PDF_PageSize_RA1 = 14
      #PBEx_PDF_PageSize_RA2 = 15
      #PBEx_PDF_PageSize_RA3 = 16
      #PBEx_PDF_PageSize_RA4 = 17
      #PBEx_PDF_PageSize_RA5 = 18
      
      CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
        PBEx_PDF = OpenLibrary(#PB_Any, "PB.Ex_PDF_x86.dll")
      CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
        PBEx_PDF = OpenLibrary(#PB_Any, "PB.Ex_PDF_x64.dll")
      CompilerEndIf
      
      If PBEx_PDF
        Prototype CreatePDF(ID, ErrorOutput)
        Global CreatePDF.CreatePDF = GetFunction(PBEx_PDF, "CreatePDF")
        Prototype SetPDFTitle(ID, Title.p-Unicode, ErrorOutput)
        Global SetPDFTitle.SetPDFTitle = GetFunction(PBEx_PDF, "SetPDFTitle")
        Prototype SetPDFAuthor(ID, Author.p-Unicode, ErrorOutput)
        Global SetPDFAuthor.SetPDFAuthor = GetFunction(PBEx_PDF, "SetPDFAuthor")
        Prototype SetPDFSubject(ID, Subject.p-Unicode, ErrorOutput)
        Global SetPDFSubject.SetPDFSubject = GetFunction(PBEx_PDF, "SetPDFSubject")
        Prototype SetPDFKeywords(ID, Keywords.p-Unicode, ErrorOutput)
        Global SetPDFKeywords.SetPDFKeywords = GetFunction(PBEx_PDF, "SetPDFKeywords")
        Prototype SetPDFCreator(ID, Creator.p-Unicode, ErrorOutput)
        Global SetPDFCreator.SetPDFCreator = GetFunction(PBEx_PDF, "SetPDFCreator")
        Prototype GetPDFTitle(ID, Output, ErrorOutput)
        Global GetPDFTitle.GetPDFTitle = GetFunction(PBEx_PDF, "GetPDFTitle")
        Prototype GetPDFAuthor(ID, Output, ErrorOutput)
        Global GetPDFAuthor.GetPDFAuthor = GetFunction(PBEx_PDF, "GetPDFAuthor")
        Prototype GetPDFSubject(ID, Output, ErrorOutput)
        Global GetPDFSubject.GetPDFSubject = GetFunction(PBEx_PDF, "GetPDFSubject")
        Prototype GetPDFKeywords(ID, Output, ErrorOutput)
        Global GetPDFKeywords.GetPDFKeywords = GetFunction(PBEx_PDF, "GetPDFKeywords")
        Prototype GetPDFCreator(ID, Output, ErrorOutput)
        Global GetPDFCreator.GetPDFCreator = GetFunction(PBEx_PDF, "GetPDFCreator")
        Prototype AddPDFText(ID, Text.p-Unicode, ErrorOutput)
        Global AddPDFText.AddPDFText = GetFunction(PBEx_PDF, "AddPDFText")
        Prototype SavePDF(ID, Path.p-Unicode, ErrorOutput)
        Global SavePDF.SavePDF = GetFunction(PBEx_PDF, "SavePDF")
        Prototype AddPDFPage(ID, ErrorOutput)
        Global AddPDFPage.AddPDFPage = GetFunction(PBEx_PDF, "AddPDFPage")
        Prototype ClosePDF(ID, ErrorOutput)
        Global ClosePDF.ClosePDF = GetFunction(PBEx_PDF, "ClosePDF")
        Prototype IsPDF(ID, ErrorOutput)
        Global IsPDF.IsPDF = GetFunction(PBEx_PDF, "IsPDF")
        Prototype SetPDFFont(ID, FontName.p-Unicode, FontSize, FontStyle, ErrorOutput)
        Global SetPDFFont.SetPDFFont = GetFunction(PBEx_PDF, "SetPDFFont")
        Prototype ProtectPDF(ID, UserPassword.p-Unicode, OwnerPassword.p-Unicode, PermissionForExtract, PermissionForModification, PermissionForFormFill, PermissionForAnnotation, PermissionForPrint, PermissionForPrintFullQuality, ErrorOutput)
        Global ProtectPDF.ProtectPDF = GetFunction(PBEx_PDF, "ProtectPDF")
        Prototype OpenPDF(ID, Path.p-Unicode, Password.p-Unicode, ErrorOutput)
        Global OpenPDF.OpenPDF = GetFunction(PBEx_PDF, "OpenPDF")
        Prototype GetPDFPageTotal(ID, ErrorOutput)
        Global GetPDFPageTotal.GetPDFPageTotal = GetFunction(PBEx_PDF, "GetPDFPageTotal")
        Prototype SetPDFPageSize(ID, Size, Orientation, ErrorOutput)
        Global SetPDFPageSize.SetPDFPageSize = GetFunction(PBEx_PDF, "SetPDFPageSize")
        Prototype GetPDFPageSize(ID, ErrorOutput)
        Global GetPDFPageSize.GetPDFPageSize = GetFunction(PBEx_PDF, "GetPDFPageSize")
        Prototype GetPDFPageOrientation(ID, ErrorOutput)
        Global GetPDFPageOrientation.GetPDFPageOrientation = GetFunction(PBEx_PDF, "GetPDFPageOrientation")
        Prototype SetPDFPageMargin(ID, Top, Right, Bottom, Left, ErrorOutput)
        Global SetPDFPageMargin.SetPDFPageMargin = GetFunction(PBEx_PDF, "SetPDFPageMargin")
        Prototype SetPDFTextColor(ID, Color, ErrorOutput)
        Global SetPDFTextColor.SetPDFTextColor = GetFunction(PBEx_PDF, "SetPDFTextColor")
        Prototype AddPDFImage(ID, Path.p-Unicode, X, Y, Width, Height, ErrorOutput)
        Global AddPDFImage.AddPDFImage = GetFunction(PBEx_PDF, "AddPDFImage")
        
      EndIf
      
      Define Output$ = Space(1000000)
      Define ErrorOutput$ = ""
      Define MyText$ = ""
      
      MyText$ + "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor." + Chr(13)
      MyText$ + "Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus." + Chr(13)
      MyText$ + "Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem." + Chr(13)
      MyText$ + Chr(13)
      MyText$ + "Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus." + Chr(13)
      MyText$ + Chr(13)
      MyText$ + "Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue."
      
      If CreatePDF(1, @ErrorOutput$)
        SetPDFTitle(1, "My title", @ErrorOutput$)
        SetPDFAuthor(1, "RSBasic", @ErrorOutput$)
        SetPDFSubject(1, "My title", @ErrorOutput$)
        SetPDFTitle(1, "My title", @ErrorOutput$)
        SetPDFKeywords(1, "pb, html, cpp, js, asm, vb", @ErrorOutput$)
        SetPDFCreator(1, "RSBasic", @ErrorOutput$)
        
        SetPDFPageSize(1, #PBEx_PDF_PageSize_A4, #PBEx_PDF_PageOrientation_Portrait, @ErrorOutput$)
        SetPDFPageMargin(1, 50, 50, 50, 50, @ErrorOutput$)
        SetPDFFont(1, "Arial", 16, 0, @ErrorOutput$)
        SetPDFTextColor(1, RGBA(0, 0, 0, 255), @ErrorOutput$)
        AddPDFText(1, MyText$, @ErrorOutput$)
        
        AddPDFPage(1, @ErrorOutput$)
        SetPDFPageSize(1, #PBEx_PDF_PageSize_A3, #PBEx_PDF_PageOrientation_Landscape, @ErrorOutput$)
        SetPDFFont(1, "Courier", 20, #PB_Font_Underline | #PB_Font_Italic, @ErrorOutput$)
        SetPDFTextColor(1, RGBA(255, 0, 0, 150), @ErrorOutput$)
        AddPDFText(1, "Hello PureBasic Friends. How are you?", @ErrorOutput$)
        
        SavePDF(1, GetCurrentDirectory() + "MyPDF.pdf", @ErrorOutput$)
        
        ClosePDF(1, @ErrorOutput$)
        
        RunProgram(GetCurrentDirectory() + "MyPDF.pdf")
        
      EndIf
      
      CloseLibrary(PBEx_PDF)
  • OpenPDF()
    • Syntax:

      Code: Select all

      Result = OpenPDF(ID, Path$, Password$, @ErrorOutput$)
    • Description: Opens an existing PDF document.
    • Parameter:
      1. ID: A unique number for the document. #PB_Any can be used to generate the number automatically.
      2. Path$: The full path to the PDF document you want to open.
      3. Password$: If the PDF document is protected, the password must be entered here.
      4. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • SetPDFTitle()
    • Syntax:

      Code: Select all

      Result = SetPDFTitle(ID, Title$, @ErrorOutput$)
    • Description: Defines the title (Meta property).
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Title$: Title
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • SetPDFAuthor()
    • Syntax:

      Code: Select all

      Result = SetPDFAuthor(ID, Author$, @ErrorOutput$)
    • Description: Sets the author name (Meta property).
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Author$: Name of author
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • SetPDFSubject()
    • Syntax:

      Code: Select all

      Result = SetPDFSubject(ID, Subject$, @ErrorOutput$)
    • Description: Specifies the subject (Meta property).
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Subject$: Subject
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • SetPDFKeywords()
    • Syntax:

      Code: Select all

      Result = SetPDFKeywords(ID, Keywords$, @ErrorOutput$)
    • Description: Defines the keywords (meta property).
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Keywords$: Keywords can be added with commas.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • SetPDFCreator()
    • Syntax:

      Code: Select all

      Result = SetPDFCreator(ID, Creator$, @ErrorOutput$)
    • Description: Specifies the creator (Meta property).
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Creator$: The name of the creator of this PDF document.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • GetPDFTitle()
    • Syntax:

      Code: Select all

      Result = GetPDFTitle(ID, @Output$, @ErrorOutput$)
    • Description: Determines the title. (Meta Property)
    • Parameter:
      1. ID: The number of the created or opened document.
      2. @Output$: The return value is saved in this variable.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • GetPDFAuthor()
    • Syntax:

      Code: Select all

      Result = GetPDFAuthor(ID, @Output$, @ErrorOutput$)
    • Description: Get the author. (Meta Property)
    • Parameter:
      1. ID: The number of the created or opened document.
      2. @Output$: The return value is stored in this variable.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • GetPDFSubject()
    • Syntax:

      Code: Select all

      Result = GetPDFSubject(ID, @Output$, @ErrorOutput$)
    • Description: Determines the subject. (Meta Property)
    • Parameter:
      1. ID: The number of the created or opened document.
      2. @Output$: The return value is stored in this variable.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • GetPDFKeywords()
    • Syntax:

      Code: Select all

      Result = GetPDFKeywords(ID, @Output$, @ErrorOutput$)
    • Description: Determines the keywords. (Meta Property)
    • Parameter:
      1. ID: The number of the created or opened document.
      2. @Output$: The return value is stored in this variable.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • GetPDFCreator()
    • Syntax:

      Code: Select all

      Result = GetPDFCreator(ID, @Output$, @ErrorOutput$)
    • Description: Determines the creator. (Meta Property)
    • Parameter:
      1. ID: The number of the created or opened document.
      2. @Output$: The return value is stored in this variable.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • AddPDFText()
    • Syntax:

      Code: Select all

      Result = AddPDFText(ID, Text$, @ErrorOutput$)
    • Description: Inserts a text on the current page.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Text$: The text to be inserted. Line breaks with Chr(13) are possible.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • AddPDFImage()
    • Syntax:

      Code: Select all

      Result = AddPDFImage(ID, Path$, X, Y, Width, Height, @ErrorOutput$)
    • Description: Inserts an image on the current page.
    • Parameter:
      1. ID: The number of the document created or opened.
      2. Path$: Full path to the image file.
      3. X: X position where the image will be inserted.
      4. Y: Y position where the image will be inserted.
      5. Width: Width of the image. If -1 is specified, the width of the image is determined proportionally. If -1 is specified for width and height, then the original size is determined.
      6. Height: Height of the image. If -1 is specified, the width of the image is determined proportionally. If -1 is specified for width and height, then the original size is determined.
      7. @ErrorOutput$: If an error occurs, the error message is saved to the string variable.
    • Return value:
      • 1: The process was successful.
  • SavePDF()
    • Syntax:

      Code: Select all

      Result = SavePDF(ID, Path$, @ErrorOutput$)
    • Description: Saves the created or opened PDF document with all changes.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Path$: Complete path incl. file name.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • AddPDFPage()
    • Syntax:

      Code: Select all

      Result = AddPDFPage(ID, @ErrorOutput$)
    • Description: Adds a new blank page. Texts that are added afterwards now appear on the new page.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • ClosePDF()
    • Syntax:

      Code: Select all

      Result = ClosePDF(ID, @ErrorOutput$)
    • Description: Closes the created or opened PDF document. Unsaved changes are lost and all objects are released.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • IsPDF()
    • Syntax:

      Code: Select all

      Result = IsPDF(ID, @ErrorOutput$)
    • Description: Checks whether the ID of the created or opened PDF document is still valid.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • SetPDFFont()
    • Syntax:

      Code: Select all

      Result = SetPDFFont(ID, FontName$, FontSize, FontStyle, @ErrorOutput$)
    • Description: Specifies the font, font size, and font formatting. Texts that are added afterwards receive the new font.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. FontName$: Font name
      3. FontSize: Size of the font in pixels
      4. FontStyle: The following constants can be used:
        • #PB_Font_Bold: Bold
        • #PB_Font_Italic: Italic
        • #PB_Font_Underline: Underline
        • #PB_Font_StrikeOut: Strike out
      5. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • ProtectPDF()
    • Syntax:

      Code: Select all

      Result = ProtectPDF(ID, UserPassword$, OwnerPassword$, PermissionForExtract, PermissionForModification, PermissionForFormFill, PermissionForAnnotation, PermissionForPrint, PermissionForPrintFullQuality, @ErrorOutput$)
    • Description: This allows the created or opened PDF document to be protected with password protection and other authorizations. The protection can also be lifted again.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. UserPassword$: The password for normal users who are allowed to access this document.
      3. OwnerPassword$: The password for the creator. Only with this password is it possible to change permissions and cancel password protection.
      4. PermissionForExtract: Allows the user to extract the content from the document.
      5. PermissionForModification: Allows the user to change the PDF document.
      6. PermissionForFormFill: Allows the user to fill out the form fields.
      7. PermissionForAnnotation: Allows the user to add annotations within the document.
      8. PermissionForPrint: Allows the user to print.
      9. PermissionForPrintFullQuality: Allows the user to print in high quality.
      10. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • GetPDFPageTotal()
    • Syntax:

      Code: Select all

      Result = GetPDFPageTotal(ID, @ErrorOutput$)
    • Description: Determines the number of pages.
    • Parameter:
      1. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value: Number of pages
  • SetPDFPageSize()
    • Syntax:

      Code: Select all

      Result = SetPDFPageSize(ID, Size, Orientation, @ErrorOutput$)
    • Description: Defines the page size and orientation.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Size: The following paper sizes can be used:
        • #PBEx_PDF_PageSize_A0
        • #PBEx_PDF_PageSize_A1
        • #PBEx_PDF_PageSize_A2
        • #PBEx_PDF_PageSize_A3
        • #PBEx_PDF_PageSize_A4
        • #PBEx_PDF_PageSize_A5
        • #PBEx_PDF_PageSize_B0
        • #PBEx_PDF_PageSize_B1
        • #PBEx_PDF_PageSize_B2
        • #PBEx_PDF_PageSize_B3
        • #PBEx_PDF_PageSize_B4
        • #PBEx_PDF_PageSize_B5
        • #PBEx_PDF_PageSize_RA0
        • #PBEx_PDF_PageSize_RA1
        • #PBEx_PDF_PageSize_RA2
        • #PBEx_PDF_PageSize_RA3
        • #PBEx_PDF_PageSize_RA4
        • #PBEx_PDF_PageSize_RA5
      3. Orientation: The following orientation can be used:
        • #PBEx_PDF_PageOrientation_Portrait: Portrait
        • #PBEx_PDF_PageOrientation_Landscape: Landscape
      4. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • GetPDFPageSize()
    • Syntax:

      Code: Select all

      Result = GetPDFPageSize(ID, @ErrorOutput$)
    • Description: Determines the page size.
    • Parameter:
      1. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value: The value can be evaluated with the following constants:
      • #PBEx_PDF_PageSize_A0
      • #PBEx_PDF_PageSize_A1
      • #PBEx_PDF_PageSize_A2
      • #PBEx_PDF_PageSize_A3
      • #PBEx_PDF_PageSize_A4
      • #PBEx_PDF_PageSize_A5
      • #PBEx_PDF_PageSize_B0
      • #PBEx_PDF_PageSize_B1
      • #PBEx_PDF_PageSize_B2
      • #PBEx_PDF_PageSize_B3
      • #PBEx_PDF_PageSize_B4
      • #PBEx_PDF_PageSize_B5
      • #PBEx_PDF_PageSize_RA0
      • #PBEx_PDF_PageSize_RA1
      • #PBEx_PDF_PageSize_RA2
      • #PBEx_PDF_PageSize_RA3
      • #PBEx_PDF_PageSize_RA4
      • #PBEx_PDF_PageSize_RA5
  • GetPDFPageOrientation()
    • Syntax:

      Code: Select all

      Result = GetPDFPageOrientation(ID, @ErrorOutput$)
    • Description: Determines the orientation
    • Parameter:
      1. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value: The value can be evaluated with the following constants:
      • #PBEx_PDF_PageOrientation_Portrait: Portrait
      • #PBEx_PDF_PageOrientation_Landscape: Landscape
  • SetPDFPageMargin()
    • Syntax:

      Code: Select all

      Result = SetPDFPageMargin(ID, Top, Right, Bottom, Left, @ErrorOutput$)
    • Description: Determines the outer margins
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Top: Top margin
      3. Right: Right margin
      4. Bottom: Bottom margin
      5. Left: Left margin
      6. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • SetPDFTextColor()
    • Syntax:

      Code: Select all

      Result = SetPDFTextColor(ID, Color, @ErrorOutput$)
    • Description: Sets the font color. Texts that are added afterwards are given the new color.
    • Parameter:
      1. ID: The number of the created or opened document.
      2. Color: RGB() or RGBA() can be used for color definition.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Return value:
      • 1: The process was successful.
  • SetPDFPage()
    • Syntax:

      Code: Select all

      Result = SetPDFPage(ID, PageNumber, @ErrorOutput$)
    • Description: Set the page to write on.
    • Parameter:
      1. ID: The number of the document created or opened.
      2. PageNumber: Page number. Starting 1.
      3. @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
    • Rückgabewert:
      • 1: The process was successful.
System requirements:
  • .NET Framework 4.7.2 or higher
  • Unicode activation (default from PB 5.50)
Licence: This DLL file is free of charge and may be used both privately and commercially.
The following copyright texts must be provided:
Copyright (c) 2005-2014 empira Software GmbH, Troisdorf (Germany)
Copyright © 2019 RSBasic.de
Download: https://www.rsbasic.de/downloads/downlo ... Ex_PDF.zip
Image

I would be very pleased about feedbacks, improvement suggestions, error messages or wishes. If you want to support me, you can also donate me a little something. Thanks :)
Image
Image
m4u
New User
New User
Posts: 5
Joined: Mon Dec 31, 2018 8:47 am

Re: PB.Ex PDF (Windows)

Post by m4u »

Looks promising. It works fine once an .exe is compiled/created in the same directory as the .DLL libraries reside.

However: I open the .pb file in Purebasic, run it and get:
  • Executable started.
    [ERROR] Line: 98
    [ERROR] Invalid memory access. (read error at address 0)
This line:

Code: Select all

33 If PBEx_PDF
has no ElseIf. If the .DLLs are not in the compiled directory, then line 98 forces an error. Maybe add a "ElseIF" statement?

I'll check the functions this weekend.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PB.Ex PDF (Windows)

Post by Kwai chang caine »

For me works perfectly on W10 X64 / V5.70 x86
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: PB.Ex PDF (Windows)

Post by BarryG »

RSBasic wrote:.NET Framework 4.5 or higher
Does this mean I have to install .NET (if missing) on the target PC? I use PureBasic because of no dependencies and standalone executables for my products... so this concerns me. Or is it just a DLL that I need to sit next my exe in my product's folder?
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: PB.Ex PDF (Windows)

Post by RSBasic »

You need .NET framework and my DLL file. Many applications from the Internet are based on .NET and it has been standard for years and preinstalled on current operating systems.
Image
Image
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: PB.Ex PDF (Windows)

Post by BarryG »

RSBasic wrote:You need .NET framework
Thanks for clarifying.
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: PB.Ex PDF (Windows)

Post by RSBasic »

PB.Ex PDF 1.0.1.0 has been released.

Changelog:
  • Added: AddPDFImage()
  • Updated: .NET Framework 3.5 > .NET Framework 4.7.2
Image
Image
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: PB.Ex PDF (Windows)

Post by Quin »

Just tested, works for me on Windows 10, PB 6.10. Quite well done! :)
BeePee
New User
New User
Posts: 2
Joined: Mon Jan 30, 2023 9:53 am

Re: PB.Ex PDF (Windows)

Post by BeePee »

Hello,
I would like to add some text to an existing PDF file.
When I run the AddPDFText function, I get the error message
"The value cannot be null. Parameter name page."
I think I need to specify on which page to place the text.
Can you tell me which method to use?
Thanks for your help.
Best regards.
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: PB.Ex PDF (Windows)

Post by RSBasic »

PB.Ex PDF 1.0.2.0 has been released.

Changelog:
  • Added: SetPDFPage(): Set the page to write on.
@BeePee
You first have to create a new page with AddPDFPage(), then you can insert text.
But I added a new function SetPDFPage() so you can set which page you want to write on.

Example:

Code: Select all

Define Output$ = Space(1000000)
Define ErrorOutput$ = Space(1000000)

If OpenPDF(1, "Example2.pdf", "", @ErrorOutput$) > 0
  SetPDFPageSize(1, #PBEx_PDF_PageSize_A3, #PBEx_PDF_PageOrientation_Landscape, @ErrorOutput$)
  SetPDFFont(1, "Courier", 20, #PB_Font_Underline | #PB_Font_Italic, @ErrorOutput$)
  SetPDFTextColor(1, RGBA(255, 0, 0, 150), @ErrorOutput$)
  
  SetPDFPage(1, 1, @ErrorOutput$)
  SetPDFPageMargin(1, 50, 0, 0, 250, @ErrorOutput$)
  AddPDFText(1, "Hello PureBasic", @ErrorOutput$)
  
  SetPDFPage(1, 2, @ErrorOutput$)
  SetPDFPageMargin(1, 250, 0, 0, 50, @ErrorOutput$)
  AddPDFText(1, "Another Text", @ErrorOutput$)
  
  SavePDF(1, "Example2_Edit.pdf", @ErrorOutput$)
  
  ClosePDF(1, @ErrorOutput$)
Else
  Debug ErrorOutput$
EndIf

CloseLibrary(PBEx_PDF)
Result:
Image
Image
Image
Post Reply