[Module] pbPDF-Module

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

[Module] pbPDF-Module

Post by Thorsten1867 »

pbPDF - Module

Creating PDF documents
  • Support of form fields (e.g. text field, checkbox, radio button & combo box)
  • Encryption (password protection & access permissions)
  • Using the PB Packer Library instead of external compression procedures
  • Reading font and image headers only with PB commands instead of with Windows API
  • JPEG2000 image format support
  • Unicode character set support
  • 64-bit compatible

Code: Select all

  ; ----- Basic Commands -----

  ; PDF::Create()                      - Create PDF document.
  ; PDF::AddPage()                     - Adds a (new) page to the document.
  ; PDF::BookMark()                    - Add bookmark
  ; PDF::Cell()                        - Prints a cell (rectangular area) with optional borders, background color and character string.
  ; PDF::DividingLine()                - Draws a line with the specified width.
  ; PDF::GetFontSize()                 - Get current fontsize (#Point/#Unit)
  ; PDF::GetMargin()                   - Get left, top, right or cell margin.
  ; PDF::GetMultiCellLines()           - Get the last value of newlines for pdf_MultiCell()
  ; PDF::GetPageHeight()               - Get current height of page.
  ; PDF::GetPageNumber()               - Returns the current page number.
  ; PDF::GetPageWidth()                - Get current width of page. 
  ; PDF::GetPosX()                     - Returns the abscissa of the current position.
  ; PDF::GetPosY()                     - Returns the ordinate of the current position.
  ; PDF::GetStringWidth()              - Get width of a string in the current font.
  ; PDF::Image()                       - Puts an image in the page.
  ; PDF::Ln()                          - Performs a line break.
  ; PDF::MultiCell()                   - This method allows printing text with line breaks.
  ; PDF::MultiCellList()               - Add multicell with list elements
  ; PDF::PlaceText()                   - Place text at x, y position.  
  ; PDF::Rotate()                      - Perform a rotation around a given center.
  ; PDF::Save()                        - Save PDF under file name
  ; PDF::SetAutoPageBreak()            - Set auto page break mode and triggering margin.
  ; PDF::SetColorRGB()                 - Set RGB color for text, draw and fill  (#TextColor / #DrawColor / #FillColor).
  ; PDF::SetDashedLine()               - Set a dash pattern and draw dashed lines or rectangles.
  ; PDF::SetFont()                     - Sets the font used to print character strings.
  ; PDF::SetFontSize()                 - Defines the size of the current font.
  ; PDF::SetPageNumbering()            - Set page numbering in footer #True/#False.
  ; PDF::SetInfo()                     - Defines author, titel, subject, creator and associated keywords ('keyword1 keyword2 ...') of the document
  ; PDF::SetLineThickness()            - Defines the line thickness.
  ; PDF::SetMargin()                   - Set left, top, right or cell margin.
  ; PDF::SetPageMargins()              - Set left, top and right page margins.
  ; PDF::SetPosXY()                    - Defines the abscissa and ordinate of the current position.
  ; PDF::SetPosX()                     - Defines the abscissa of the current position. 
  ; PDF::SetPosY()                     - Moves the current abscissa back to the left margin and sets the ordinate.
  ; PDF::SubWrite()                    - Write superscripted or supscripted
  ; PDF::TruncateCell()                - Prints a Cell, if text is too large it will be truncated
  ; PDF::Write()                       - This method prints text from the current position.
  
  ; ----- Advanced Commands -----
  
  ; PDF::EmbedFile()                   - Embeds a file into the pdf.
  ; PDF::EmbedFont()                   - Embeds a font into the pdf and returns the font name.
  ; PDF::EmbedJavaScript()             - Add JavaScript
  ; PDF::EmbedJavaScriptFile()         - Include JavaScript file
  ; PDF::EnableFooter()                - Enable/disable Footer (procedure)
  ; PDF::EnableHeader()                - Enable/disable Header (procedure)
  ; PDF::EnableTOCNums()               - Enable/disable adding page numbers to table of contents
  ; PDF::AddEntryTOC()                 - Add TOC entry
  ; PDF::EscapeText()                  - Format a text string (=> masked string).
  ; PDF::GetErrorCode()                - Return the error code.
  ; PDF::GetErrorMessage()             - Return the error message.    
  ; PDF::GetNumbering()                - Return if numbering is #True/#False. Usefull for TOC functions
  ; PDF::GetObjectNum()                - Get object number
  ; PDF::GetScaleFactor()              - Get scale factor for used unit.
  ; PDF::GetWordSpacing()              - Get word spacing.  
  ; PDF::ImageMemory()                 - Puts an image (Memory) in the page.
  ; PDF::InsertTOC()                   - Insert table of contents.
  ; PDF::Link()                        - Puts a link on a rectangular area of the page.
  ; PDF::SetAliasTotalPages()          - Defines an alias for the total number of pages.
  ; PDF::SetColorCMYK()                - Set CMYK color for text, draw and fill (#TextColor / #DrawColor / #FillColor).
  ; PDF::SetEncryption()               - Enable encryption and set passworts and permission
  ; PDF::SetFooterProcedure()          - Set footer procedure.
  ; PDF::SetHeaderProcedure()          - Set header procedure.
  ; PDF::SetOpenAction()               - Set page and zoom for opening the document
  ; PDF::SetPageCompression()          - Enable/disable compression for pages
  ; PDF::SetPageLayout()               - Define display mode for pages in the viewer
  ; PDF::SetPageMode()                 - Define mode and appearance of the viewer (e.g. fullscreen mode)
  ; PDF::SetViewerPreferences()        - Set viewer preferences
  ; PDF::SetWordSpacing()              - Set word spacing. 
  
  ; ----- AcroForms [#Enable_AcroFormCommands] ------
  
  ; PDF::ButtonField()                 - Button field (PushButton / CheckBox / RadioButton)
  ; PDF::ChoiceField()                 - Choice field (Scrolling List / ComboBox / editable ComboBox)
  ; PDF::TextField()                   - Text field   (single line/ multiline)
  
  ; ----- Annotations & Actions [#Enable_Annotations] -----
  
  ; PDF::AddFileLink()                 - Defines the page and position for embedded file annotations. (#GraphIcon/#PaperClipIcon/#PushPinIcon/#TagIcon)
  ; PDF::AddGotoAction()               - Goto page and position in the document
  ; PDF::AddGotoLabel()                - Set Label to be able to jump to this position
  ; PDF::AddLaunchAction()             - Defines the page and position for a launch action. (#OpenAction/#PrintAction)
  ; PDF::AddLinkURL)                   - Defines the page and position a link points to and returns its identifier.
  ; PDF::AddTextNote()                 - Defines the page and position for text annotations. ( #CommentIcon/#KeyIcon/#NoteIcon/#HelpIcon/#NewParagraphIcon/#ParagraphIcon/#InsertIcon )
  
  ; ----- Drawing Commands [#Enable_DrawingCommands] -----
  
  ; PDF::DrawCircle()                  - Draws a circle
  ; PDF::DrawEllipse()                 - Draws a ellipse
  ; PDF::DrawGrid()                    - Draws a light blue grid on the page for testing purposes
  ; PDF::DrawLine()                    - Draws a single line between two points.
  ; PDF::DrawRectangle()               - Draws a rectangle.
  ; PDF::DrawRoundedRectangle()        - Draws a rounded rectangle.
  ; PDF::DrawSector()                  - Draws the sector of a circle.
  ; PDF::DrawTriangle()                - Draws a triangle
  
  ; PDF::SetLineCap()                  - Sets the line cap style
  ; PDF::SetLineCorner()               - Sets the line join style.
  
  ; PDF::PathArc()                     - Draws a cubic Bezier curve to the current path.
  ; PDF::PathBegin()                   - Begins a new path at the coordinates (x, y).
  ; PDF::PathEnd()                     - Closes the current path and draws a line from the current point to the starting point.
  ; PDF::PathLine()                    - Draws a line from the current point to (x, y).
  ; PDF::PathRect()                    - Draws a rectangle to the current path with upper-left corner (x, y) and dimensions (w, h). 
  
  ; ----- Transformation [#Enable_TransformCommands] -----
  
  ; PDF::StartTransform()              - Use this before calling any transformation. (Scale, Skew, Mirror, Translate)
  ; PDF::StopTransform()               - Restore the normal painting And placing behaviour As it was before calling pdf_StartTransform(). 
  ; PDF::MirrorHorizontal()            - Alias for scaling -100% in x direction. (Transform)
  ; PDF::MirrorVertical()              - Alias For scaling -100% in y direction. (Transform)
  ; PDF::ScaleHorizontal()             - Scaling horizontal        (Transform)
  ; PDF::ScaleVertical()               - Scaling vertical          (Transform)
  ; PDF::Scale()                       - Scaling                   (Transform)
  ; PDF::SkewHorizontal()              - Skewing -> angle x        (Transform)
  ; PDF::SkewVertical()                - Skewing -> angle y        (Transform)
  ; PDF::Translate()                   - Translate -> right/bottom (Transform)
  ; PDF::TranslateHorizontal()         - Translate -> right        (Transform)
  ; PDF::TranslateVertical()           - Translate -> bottom       (Transform)
  
Download: pbPDFModule.pbi
Last edited by Thorsten1867 on Sat Nov 23, 2019 1:05 pm, edited 7 times in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: [Module] pbPDF-Module

Post by Andre »

Looks very powerful! Thank you very much :D

Hint: You should change the first line in your example codes to the following, as they are placed in a sub-folder "Examples", while the include file is in the parent drawer:
XIncludeFile "../pbPDFModule.pbi"
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: [Module] pbPDF-Module

Post by Kwai chang caine »

Thanks a lot for sharing this usefull works 8)
ImageThe happiness is a road...
Not a destination
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

Added:
Password Protection & Encryption
Access permissions for PDF documents
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: [Module] pbPDF-Module

Post by loulou2522 »

Problem when reading a file created with your programm :
Error message

Code: Select all

Error when reading this file 14
Environement :
Compiling with Purebasic 70 X86 version
Reading with Adobe acrobat reader version 20
Windows 10
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

I created a new (hopefully error-free) ZIP file for download.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: [Module] pbPDF-Module

Post by loulou2522 »

PDF::AddLaunchAction
doesn't work in your example PbPDF-Actions.pb ligne 26
respond

Code: Select all

can't open file 20k_C2.txt
In PBpdf_Pagesformat.pb
Ligne 30 error message Module element GetPageHeigth unkown
Last edited by loulou2522 on Wed Jan 23, 2019 11:21 am, edited 1 time in total.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

Which PDF viewer did you use? Some don't seem to support all file types.



Gesendet von meinem Aquaris X2 mit Tapatalk
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: [Module] pbPDF-Module

Post by loulou2522 »

Acrobat Reader DC v 20
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

I'll test it at home.

Gesendet von meinem Aquaris X2 mit Tapatalk
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: [Module] pbPDF-Module

Post by loulou2522 »

I find the errror in your programm PB_pdf_Pageformat.pb

Ligne 30, 34 and 38 GetPageHeight is uncorrectly written
PDF::Cell(#PDF, StrF(PDF::GetPageWidth(#PDF), 0) + "x" + StrF(PDF::GetPageHeigth(#PDF), 0) + " mm", 40, 10, #True)

instead of
PDF::Cell(#PDF, StrF(PDF::GetPageWidth(#PDF), 0) + "x" + StrF(PDF::GetPageHeight(#PDF), 0) + " mm", 40, 10, #True)

For the launching of file i can't solve it
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

loulou2522 wrote:PDF::AddLaunchAction
doesn't work in your example PbPDF-Actions.pb ligne 26
respond

Code: Select all

can't open file 20k_C2.txt
In PBpdf_Pagesformat.pb
Ligne 30 error message Module element GetPageHeigth unkown
It works for me.
Probably the file type (*.txt) is not linked to any program.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: [Module] pbPDF-Module

Post by Justin »

This looks great, can it be used to join existing pdf files?
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] pbPDF-Module

Post by Thorsten1867 »

Unfortunately this is not possible, you can only create your own PDF documents.
You need a tool like "pdftk".
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: [Module] pbPDF-Module

Post by Justin »

Ok thanks.
Post Reply