B4A Library PDFWriter

Hello everyone,

Here is yet another library: PDFWriter.
Linked by user mwhetmore at this topic, you can now create your own PDF files and save them!
The library has 3 declarations:

I. PDFWriter
B4X:
Dim PDFWriter1 As PDFWriter
Declare this in globals so you can benifit from all main methods for writing your PDF File.


1.1 Initialize
B4X:
PDFWriter1.Initialize("PDFWriter1",PaperSize.A4_WIDTH, PaperSize.A4_HEIGHT)

This initializes your PDF writer and gives in an eventname for when the pdf has been created, and it creates a new document with the papersizes than you can choose. (A1, A2, A3, and a lot more!).

1.2 addLine
B4X:
PDFWriter1.addLine(int fromLeft, int fromBottom, int toLeft, int toBottom)

Adds a line to your PDF file. The parameters are self-explanatory.

1.3 addRawContent
B4X:
PDFWriter1.addRawContent(String rawContent)

Adds raw content to your pdf file.
For example: PDFWriter1.addRawContent("0 1 0 rg\n")

1.4 addRectangle
B4X:
PDFWriter1.addRectangle(int fromLeft, int fromBottom, int toLeft, int toBottom)

Adds a rectangle to your pdf file.

1.5 addText
B4X:
PDFWriter1.addText(int leftPosition, int topPositionFromBottom, int fontSize, String text)
PDFWriter1.addText2(int leftPosition, int topPositionFromBottom, int fontSize, String text, String transformation)

This will add text to your PDF file.
The difference between addText and addText2 is that you can add a transformation to your text, see chapter III. PDFStandardFonts.

1.6 ConverseDocument
B4X:
PDFWriter1.ConverseDocument
This wll create you a PDF file. Sub ConversionDone will be raised when the conversion has been done.

B4X:
Sub PDFWriter1_ConversionDone (Content As String)
   PDFContent = Content
   ProgressDialogHide
   ToastMessageShow("Conversion has been done.",False)
End Sub

1.7 CreateNewDocument
B4X:
PDFWriter1.CreateNewDocument(int Width, int Height)
This wll create a new PDF document with the given Width and Height in Papersizes, like in the initialize method.

1.8 newPage
B4X:
PDFWriter1.newPage
This wll create a new PDF page in the same document.

1.9 outputToFile
B4X:
PDFWriter1.outputToFile(String Directory, String FileName, String pdfContent, String encoding)
This will save your pdf content in the given Directory with the given filename with the given encoding.

B4X:
PDFWriter1.outputToFile(File.DirDefaultExternal,"myNewPDF.pdf",PDFContent,"ISO-8859-1")

2.0 outputToScreen
B4X:
PDFWriter1.outputToScreen
This will show your pdfcontent in a label. (note that it won't show the pdf itself but the content!)

B4X:
Label1.Text = PDFWriter1.outputToScreen

2.1 setFont
B4X:
PDFWriter1.setFont(String subType, String baseFont)
PDFWriter1.setFont2(String subType, String baseFont, String encoding)

This will set the font in your PDF file.
The difference between setFont and setFont2 is that you can add a encoding to your text in setFont2, see chapter III. PDFStandardFonts.




II. PDFPaperSizes
B4X:
Dim PaperSize As PDFPaperSizes

With PaperSize you can select, when you create a new document (or with initialize), what paper you would like to use to work with.
Here are all the options:

A0_WIDTH
A0_HEIGHT
A1_WIDTH
A1_HEIGHT
A2_WIDTH
A2_HEIGHT
A3_WIDTH
A3_HEIGHT
A4_WIDTH
A4_HEIGHT
A5_WIDTH
A5_HEIGHT
A6_WIDTH
A6_HEIGHT
A7_WIDTH
A7_HEIGHT
A8_WIDTH
A8_HEIGHT
A9_WIDTH
A9_HEIGHT
A10_WIDTH
A10_HEIGHT
B0_WIDTH
B0_HEIGHT
B1_WIDTH
B1_HEIGHT
B2_WIDTH
B2_HEIGHT
B3_WIDTH
B3_HEIGHT
B4_WIDTH
B4_HEIGHT
B5_WIDTH
B5_HEIGHT
B6_WIDTH
B6_HEIGHT
B7_WIDTH
B7_HEIGHT
B8_WIDTH;
B8_HEIGHT
B9_WIDTH
B9_HEIGHT
B10_WIDTH
B10_HEIGHT
LETTER_WIDTH
LETTER_HEIGHT
TABLOID_WIDTH
TABLOID_HEIGHT
LEDGER_WIDTH
LEDGER_HEIGHT
LEGAL_WIDTH
LEGAL_HEIGHT
STATEMENT_WIDTH
STATEMENT_HEIGHT
EXECUTIVE_WIDTH
EXECUTIVE_HEIGHT
FOLIO_WIDTH
FOLIO_HEIGHT
QUARTO_WIDTH
QUARTO_HEIGHT

III. PDFStandardFonts
B4X:
Dim Fonts As PDFStandardFonts

And to end, you can choose between a lot of available fonts.
I won't put them here, but it varies from Times New Roman, to Courier, and some more.

IV. License

The library is licensed under BSD!
So you just have to mention the author. (not me!)
Author: Javier Santho Domingo ([email protected])


In the attachments, you can find the library files and 2 text files:
A readme.txt and Sample.txt
The project was just to big to upload here at the forum.
So just copy the content of Sample.txt in a new Basic4Android Project and
check the PDFWriter at the right hand pane in the library tab of the IDE, and run the project.

Have fun.

Tomas
 

Attachments

  • PDFWriter1.0.zip
    18.7 KB · Views: 1,555
  • PDFWriter1.1.zip
    25.6 KB · Views: 2,686
Last edited:

DonManfred

Expert
Licensed User
Longtime User
i dont use this lib
 

Mikonios

Active Member
Licensed User
Longtime User
Hi XverhelstX,

I am trying/testing the creation of a WebLink in Pdf by sending "PDFWriter1.addRawContent"
And following the documentation of:
Http://www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf

Theoretically the following raw code should generate a PDF document that when clicked on page,
opens the browser in the defined URI.
But it does not work!!!

"PDFWriter1.ConverseDocument" may not support "WebLink URI action" ???

B4X:
%PDF-1.2
    1 0 obj
        << /Type /Annot
        /Subtype /Link
        /Rect [20 20 802 525]
        /Border [16 16 1]
            <</S/URI                          
                /URI(http://www.w3.org)     
              >>
        >>
    endobj


     trailer
     <<
      /Root 1 0 R
     >>
%%EOF
 

Tayfur

Well-Known Member
Licensed User
Longtime User
Hi XverhelstX,

I am trying/testing the creation of a WebLink in Pdf by sending "PDFWriter1.addRawContent"
And following the documentation of:
Http://www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf

Theoretically the following raw code should generate a PDF document that when clicked on page,
opens the browser in the defined URI.
But it does not work!!!

"PDFWriter1.ConverseDocument" may not support "WebLink URI action" ???

B4X:
%PDF-1.2
    1 0 obj
        << /Type /Annot
        /Subtype /Link
        /Rect [20 20 802 525]
        /Border [16 16 1]
            <</S/URI                         
                /URI(http://www.w3.org)    
              >>
        >>
    endobj


     trailer
     <<
      /Root 1 0 R
     >>
%%EOF

Hello I used like this. And it code works with web link on link words.
Sample result PDF page in attachment.
B4X:
PDFWriter1.addText2(PaperSize.LETTER_WIDTH-40,50,8,"©Copyright 2016 || Download link = https://play.google.com/store/apps/details?id=profil.boru",DEGREES_270_ROTATION)
 

Attachments

  • Pipe_Profile_Result_Page.pdf
    256.2 KB · Views: 263

Mikonios

Active Member
Licensed User
Longtime User
I dont see the uri action. When I click over http no go on, neither open navigator to the uri defined. You write and paint URL text. But is not sensible at click on.
Can you try this one ???

TryThisOne.png
 

Attachments

  • DOC-20170107-WA0000.pdf
    1.3 KB · Views: 247
Last edited:

Mikonios

Active Member
Licensed User
Longtime User
Sorry. You are reason. No From my android Pdf viwer but Ok work over machine desktop.
Trying your solution and thank you very much !!!!
 

Mikonios

Active Member
Licensed User
Longtime User
True DonManfred.
With PC all work fine, problem is android.
if you copy both Pdf documents to android:::
with Pipe_Profile_Result_Page.pdf over android no work URI action.
with DOC-20170107-WA0000.pdf over android work fine URI action.
DOC-20170107-WA0000.pdf is make with PdfJet over android!!!
I can't use PdfJet because have Dexter Err !!!. My App is Big.

And yo can see other diference over PC into follow image.
The hand. Why ?? Library is old ?? Library is not compliance ??

DiferenceLnk.png
 
Last edited:

Mr Blue Sky

Active Member
Licensed User
Longtime User
For people who ask the same question and who does not answer as all the time, I can not find a better solution.
I use : RSImageProcessing Library

Private Test1 As Bitmap
Dim rbmp As RSImageProcessing

If File.Exists(File.DirRootExternal,"test.jpg" ) Then
Test1 = (LoadBitmapSample(File.DirRootExternal, "test.jpg" , 320, 200))
Test1=rbmp.rotateBitmap(Test1, -90)
PDFWriter1.addImage(80,600,Test1)
Else
PDFWriter1.addRectangle(80, 600, 200, 320)
End If
 

wdegler

Active Member
Licensed User
Longtime User
Hello everyone,

Here is yet another library: PDFWriter.
Linked by user mwhetmore at this topic, you can now create your own PDF files and save them!
The library has 3 declarations:

I. PDFWriter
B4X:
Dim PDFWriter1 As PDFWriter
Declare this in globals so you can benifit from all main methods for writing your PDF File.


1.1 Initialize
B4X:
PDFWriter1.Initialize("PDFWriter1",PaperSize.A4_WIDTH, PaperSize.A4_HEIGHT)

This initializes your PDF writer and gives in an eventname for when the pdf has been created, and it creates a new document with the papersizes than you can choose. (A1, A2, A3, and a lot more!).

1.2 addLine
B4X:
PDFWriter1.addLine(int fromLeft, int fromBottom, int toLeft, int toBottom)

Adds a line to your PDF file. The parameters are self-explanatory.

1.3 addRawContent
B4X:
PDFWriter1.addRawContent(String rawContent)

Adds raw content to your pdf file.
For example: PDFWriter1.addRawContent("0 1 0 rg\n")

1.4 addRectangle
B4X:
PDFWriter1.addRectangle(int fromLeft, int fromBottom, int toLeft, int toBottom)

Adds a rectangle to your pdf file.

1.5 addText
B4X:
PDFWriter1.addText(int leftPosition, int topPositionFromBottom, int fontSize, String text)
PDFWriter1.addText2(int leftPosition, int topPositionFromBottom, int fontSize, String text, String transformation)

This will add text to your PDF file.
The difference between addText and addText2 is that you can add a transformation to your text, see chapter III. PDFStandardFonts.

1.6 ConverseDocument
B4X:
PDFWriter1.ConverseDocument
This wll create you a PDF file. Sub ConversionDone will be raised when the conversion has been done.

B4X:
Sub PDFWriter1_ConversionDone (Content As String)
   PDFContent = Content
   ProgressDialogHide
   ToastMessageShow("Conversion has been done.",False)
End Sub

1.7 CreateNewDocument
B4X:
PDFWriter1.CreateNewDocument(int Width, int Height)
This wll create a new PDF document with the given Width and Height in Papersizes, like in the initialize method.

1.8 newPage
B4X:
PDFWriter1.newPage
This wll create a new PDF page in the same document.

1.9 outputToFile
B4X:
PDFWriter1.outputToFile(String Directory, String FileName, String pdfContent, String encoding)
This will save your pdf content in the given Directory with the given filename with the given encoding.

B4X:
PDFWriter1.outputToFile(File.DirDefaultExternal,"myNewPDF.pdf",PDFContent,"ISO-8859-1")

2.0 outputToScreen
B4X:
PDFWriter1.outputToScreen
This will show your pdfcontent in a label. (note that it won't show the pdf itself but the content!)

B4X:
Label1.Text = PDFWriter1.outputToScreen

2.1 setFont
B4X:
PDFWriter1.setFont(String subType, String baseFont)
PDFWriter1.setFont2(String subType, String baseFont, String encoding)

This will set the font in your PDF file.
The difference between setFont and setFont2 is that you can add a encoding to your text in setFont2, see chapter III. PDFStandardFonts.




II. PDFPaperSizes
B4X:
Dim PaperSize As PDFPaperSizes

With PaperSize you can select, when you create a new document (or with initialize), what paper you would like to use to work with.
Here are all the options:



III. PDFStandardFonts
B4X:
Dim Fonts As PDFStandardFonts

And to end, you can choose between a lot of available fonts.
I won't put them here, but it varies from Times New Roman, to Courier, and some more.

IV. License

The library is licensed under BSD!
So you just have to mention the author. (not me!)
Author: Javier Santho Domingo ([email protected])


In the attachments, you can find the library files and 2 text files:
A readme.txt and Sample.txt
The project was just to big to upload here at the forum.
So just copy the content of Sample.txt in a new Basic4Android Project and
check the PDFWriter at the right hand pane in the library tab of the IDE, and run the project.

Have fun.

Tomas
 

wdegler

Active Member
Licensed User
Longtime User
I would like to run your sample of PDFWriter but I don't have the required designer .bal file. How can I obtain it?
 
Top