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:
- ID: A unique number for the document. #PB_Any can be used to generate the number automatically.
- @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)
- Syntax:
- OpenPDF()
- Syntax:
Code: Select all
Result = OpenPDF(ID, Path$, Password$, @ErrorOutput$)
- Description: Opens an existing PDF document.
- Parameter:
- ID: A unique number for the document. #PB_Any can be used to generate the number automatically.
- Path$: The full path to the PDF document you want to open.
- Password$: If the PDF document is protected, the password must be entered here.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SetPDFTitle()
- Syntax:
Code: Select all
Result = SetPDFTitle(ID, Title$, @ErrorOutput$)
- Description: Defines the title (Meta property).
- Parameter:
- ID: The number of the created or opened document.
- Title$: Title
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SetPDFAuthor()
- Syntax:
Code: Select all
Result = SetPDFAuthor(ID, Author$, @ErrorOutput$)
- Description: Sets the author name (Meta property).
- Parameter:
- ID: The number of the created or opened document.
- Author$: Name of author
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SetPDFSubject()
- Syntax:
Code: Select all
Result = SetPDFSubject(ID, Subject$, @ErrorOutput$)
- Description: Specifies the subject (Meta property).
- Parameter:
- ID: The number of the created or opened document.
- Subject$: Subject
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SetPDFKeywords()
- Syntax:
Code: Select all
Result = SetPDFKeywords(ID, Keywords$, @ErrorOutput$)
- Description: Defines the keywords (meta property).
- Parameter:
- ID: The number of the created or opened document.
- Keywords$: Keywords can be added with commas.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SetPDFCreator()
- Syntax:
Code: Select all
Result = SetPDFCreator(ID, Creator$, @ErrorOutput$)
- Description: Specifies the creator (Meta property).
- Parameter:
- ID: The number of the created or opened document.
- Creator$: The name of the creator of this PDF document.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- GetPDFTitle()
- Syntax:
Code: Select all
Result = GetPDFTitle(ID, @Output$, @ErrorOutput$)
- Description: Determines the title. (Meta Property)
- Parameter:
- ID: The number of the created or opened document.
- @Output$: The return value is saved in this variable.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- GetPDFAuthor()
- Syntax:
Code: Select all
Result = GetPDFAuthor(ID, @Output$, @ErrorOutput$)
- Description: Get the author. (Meta Property)
- Parameter:
- ID: The number of the created or opened document.
- @Output$: The return value is stored in this variable.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- GetPDFSubject()
- Syntax:
Code: Select all
Result = GetPDFSubject(ID, @Output$, @ErrorOutput$)
- Description: Determines the subject. (Meta Property)
- Parameter:
- ID: The number of the created or opened document.
- @Output$: The return value is stored in this variable.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- GetPDFKeywords()
- Syntax:
Code: Select all
Result = GetPDFKeywords(ID, @Output$, @ErrorOutput$)
- Description: Determines the keywords. (Meta Property)
- Parameter:
- ID: The number of the created or opened document.
- @Output$: The return value is stored in this variable.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- GetPDFCreator()
- Syntax:
Code: Select all
Result = GetPDFCreator(ID, @Output$, @ErrorOutput$)
- Description: Determines the creator. (Meta Property)
- Parameter:
- ID: The number of the created or opened document.
- @Output$: The return value is stored in this variable.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- AddPDFText()
- Syntax:
Code: Select all
Result = AddPDFText(ID, Text$, @ErrorOutput$)
- Description: Inserts a text on the current page.
- Parameter:
- ID: The number of the created or opened document.
- Text$: The text to be inserted. Line breaks with Chr(13) are possible.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- AddPDFImage()
- Syntax:
Code: Select all
Result = AddPDFImage(ID, Path$, X, Y, Width, Height, @ErrorOutput$)
- Description: Inserts an image on the current page.
- Parameter:
- ID: The number of the document created or opened.
- Path$: Full path to the image file.
- X: X position where the image will be inserted.
- Y: Y position where the image will be inserted.
- 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.
- 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.
- @ErrorOutput$: If an error occurs, the error message is saved to the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SavePDF()
- Syntax:
Code: Select all
Result = SavePDF(ID, Path$, @ErrorOutput$)
- Description: Saves the created or opened PDF document with all changes.
- Parameter:
- ID: The number of the created or opened document.
- Path$: Complete path incl. file name.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- 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:
- ID: The number of the created or opened document.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- 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:
- ID: The number of the created or opened document.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- 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:
- ID: The number of the created or opened document.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- 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:
- ID: The number of the created or opened document.
- FontName$: Font name
- FontSize: Size of the font in pixels
- FontStyle: The following constants can be used:
- #PB_Font_Bold: Bold
- #PB_Font_Italic: Italic
- #PB_Font_Underline: Underline
- #PB_Font_StrikeOut: Strike out
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- 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:
- ID: The number of the created or opened document.
- UserPassword$: The password for normal users who are allowed to access this document.
- OwnerPassword$: The password for the creator. Only with this password is it possible to change permissions and cancel password protection.
- PermissionForExtract: Allows the user to extract the content from the document.
- PermissionForModification: Allows the user to change the PDF document.
- PermissionForFormFill: Allows the user to fill out the form fields.
- PermissionForAnnotation: Allows the user to add annotations within the document.
- PermissionForPrint: Allows the user to print.
- PermissionForPrintFullQuality: Allows the user to print in high quality.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- GetPDFPageTotal()
- Syntax:
Code: Select all
Result = GetPDFPageTotal(ID, @ErrorOutput$)
- Description: Determines the number of pages.
- Parameter:
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value: Number of pages
- Syntax:
- SetPDFPageSize()
- Syntax:
Code: Select all
Result = SetPDFPageSize(ID, Size, Orientation, @ErrorOutput$)
- Description: Defines the page size and orientation.
- Parameter:
- ID: The number of the created or opened document.
- 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
- Orientation: The following orientation can be used:
- #PBEx_PDF_PageOrientation_Portrait: Portrait
- #PBEx_PDF_PageOrientation_Landscape: Landscape
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- GetPDFPageSize()
- Syntax:
Code: Select all
Result = GetPDFPageSize(ID, @ErrorOutput$)
- Description: Determines the page size.
- Parameter:
- @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
- Syntax:
- GetPDFPageOrientation()
- Syntax:
Code: Select all
Result = GetPDFPageOrientation(ID, @ErrorOutput$)
- Description: Determines the orientation
- Parameter:
- @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
- Syntax:
- SetPDFPageMargin()
- Syntax:
Code: Select all
Result = SetPDFPageMargin(ID, Top, Right, Bottom, Left, @ErrorOutput$)
- Description: Determines the outer margins
- Parameter:
- ID: The number of the created or opened document.
- Top: Top margin
- Right: Right margin
- Bottom: Bottom margin
- Left: Left margin
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- 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:
- ID: The number of the created or opened document.
- Color: RGB() or RGBA() can be used for color definition.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SetPDFPage()
- Syntax:
Code: Select all
Result = SetPDFPage(ID, PageNumber, @ErrorOutput$)
- Description: Set the page to write on.
- Parameter:
- ID: The number of the document created or opened.
- PageNumber: Page number. Starting 1.
- @ErrorOutput$: If an error occurs, the error message is saved in the string variable.
- Rückgabewert:
- 1: The process was successful.
- Syntax:
- .NET Framework 4.7.2 or higher
- Unicode activation (default from PB 5.50)
The following copyright texts must be provided:
Download: https://www.rsbasic.de/downloads/downlo ... Ex_PDF.zipCopyright (c) 2005-2014 empira Software GmbH, Troisdorf (Germany)
Copyright © 2019 RSBasic.de
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
