[Module] pbPDF-Module

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: [Module] pbPDF-Module

Post by captain_skank »

Hi,

In the PageFormat example

Code: Select all

XIncludeFile "..\pbPDFModule.pbi"

Define File$="pbPDF-PageFormat.pdf"

#PDF = 1

Procedure Header()
  PDF::SetFont(#PDF, "Arial","B", 15)
  PDF::SetPosX(#PDF, PDF::GetPageWidth(#PDF) / 2 - 15)
  PDF::Cell(#PDF, "Title", 30, 10, 1, 0, PDF::#CenterAlign)
  PDF::Ln(#PDF, 20)
EndProcedure

Procedure Footer()
  PDF::SetFont(#PDF, "Arial", "I", 8)
  PDF::SetPosY(#PDF, -15)
  PDF::Cell(#PDF, "Page {p} / {t}", #False, 10, #False, PDF::#Right, PDF::#CenterAlign)
EndProcedure

If PDF::Create(#PDF)
  
  PDF::SetAliasTotalPages(#PDF, "{t}")
  
  PDF::SetHeaderProcedure(#PDF, @Header())  
  PDF::SetFooterProcedure(#PDF, @Footer())

  PDF::AddPage(#PDF)
  PDF::SetFont(#PDF, "Arial", "B", 16)
  PDF::Cell(#PDF, StrF(PDF::GetPageWidth(#PDF), 0) + "x" + StrF(PDF::GetPageHeight(#PDF), 0) + " mm", 40, 10, #True)
  
  PDF::AddPage(#PDF, "L", PDF::#Format_A4)
  PDF::SetFont(#PDF, "Arial", "B", 16)
  PDF::Cell(#PDF, StrF(PDF::GetPageWidth(#PDF), 0) + "x" + StrF(PDF::GetPageHeight(#PDF), 0) + " mm", 40, 10, #True)
  
  PDF::AddPage(#PDF, "L", PDF::#Format_A5)
  PDF::SetFont(#PDF, "Arial","B", 16)
  PDF::Cell(#PDF, StrF(PDF::GetPageWidth(#PDF), 0) + "x" + StrF(PDF::GetPageHeight(#PDF), 0) + " mm", 40, 10, #True)

  PDF::AddPage(#PDF, "P", PDF::#Format_A6)
  PDF::SetFont(#PDF, "Arial", "B", 16)
  PDF::Cell(#PDF, StrF(PDF::GetPageWidth(#PDF), 0) + "x" + StrF(PDF::GetPageHeight(#PDF), 0) + " mm", 40, 10, #True)
  
  PDF::Close(#PDF, File$)
EndIf

RunProgram(File$)
Yuo have the procedures for header and footer which i presume should automaticaly be applied to each page after using

Code: Select all

  PDF::SetHeaderProcedure(#PDF, @Header())  
  PDF::SetFooterProcedure(#PDF, @Footer())
However I get neither a header or footer on any page when i run the example.

Is this an error or am i doing something wrong ?

I'm using Win10 PRO x64 and Adobe Reader DC.

Cheers
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Moving inside the PDF File ; How to ?

Post by normeus »

loulou2522 wrote:I don't know how to do the following:
I'm on page 2 of my PDF and would like to go back to Page One to add text at a defined position and then go back to Page Two and continue processing. Is this possible?
once you create a new page the previous page is finalized. I set up my pages with a structure, and when I have all data then I create the final PDF.
This does sound interesting since the PDF page is just saved in memory, you'll have to reserve some space for the object, just like footer works. ( When I have time I'll take a look, but don't hold your breath)

@captain_skank
The PageFormat example is missing some code just after you set the procedures:

Code: Select all

  PDF::SetHeaderProcedure(#PDF, @Header()) 
  PDF::SetFooterProcedure(#PDF, @Footer())

  PDF::EnableFooter(#PDF, #True)   :ADD
  PDF::EnableHeader(#PDF, #True)   ;ADD
  PDF::SetPageNumbering(#PDF, #True) ;ADD
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: [Module] pbPDF-Module

Post by captain_skank »

Thanks Norm.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: [Module] pbPDF-Module

Post by captain_skank »

Right another PDF dumba$$ question.

When using

Code: Select all

PDF::MultiCell
how do you force a line break manualy ??

The help doc doesn't mention it and the original purePDF help states a linebreak can be explicitly made but doesn't say how.

Tried adding #CRLF$ or #LF$ to the string also tried including /r \r /n \n into the string but no joy.

Anybody got a clue ? :oops:

Cheers
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

That's odd, #LF$ should work, here's an example

pbPDF-Multiline.pb

Code: Select all

XIncludeFile "..\pbPDFModule.pbi"

Define File$="pbPDF-Multiline.pdf"
Define Text$, i.i
;{ These constants are defined in the module, but they did not work on my example, and I wanted a border
  #Border       = #True
  #LeftBorder   = -1
  #TopBorder    = -2
  #RightBorder  = -4
  #BottomBorder = -8
;}  
#PDF = 1


If PDF::Create(#PDF)
  
  
  PDF::AddPage(#PDF)
  
  PDF::SetFont(#PDF, "Arial", "", 12)
  
  Text$ = "PureBasic:"+#LF$+ "Is a programming language based on established BASIC rules. The key features of PureBasic are portability "
  Text$ + "(Windows, AmigaOS and Linux are currently fully supported), "+#LF$+#LF$+ "the production of very fast and highly optimized executables "
  Text$ + "and, of course, the very simple BASIC syntax. PureBasic has been created for the beginner and expert alike. We have put "
  Text$ + "a lot of effort into its realization to produce a fast, reliable and system friendly language."
  

  PDF::Cell(#PDF,"JUST A CELL"+#LF$+ " WITH NO BREAK",70,15,#Border)
  PDF::ln(#PDF)
  PDF::MultiCell(#PDF,Text$,100,5,#Border)
  PDF::ln(#PDF)
  PDF::Write(#PDF,"It also works"+#LF$+ " with write!!!")
  PDF::Close(#PDF, File$)
  
EndIf

RunProgram(File$)
I hope that helps.

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: [Module] pbPDF-Module

Post by captain_skank »

Again thanks Norm, not sure why it didn't work when i tried it.

Although I may have misunderstood the height property so set it at 20, so when I tried it using #LF$ I just got a one line cell :oops: making me think it didn't work.
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: [Module] pbPDF-Module

Post by loulou2522 »

Would it be possible to have a programming example with two form text fields A1 and A2 with javascript copying from field A1 to A2 when field A1 changes content. Thank you in advance
totorcalais
New User
New User
Posts: 8
Joined: Mon Dec 14, 2020 12:49 pm

Re: [Module] pbPDF-Module

Post by totorcalais »

Hello,

Its possible to make a pdf with Digital Signature Timestamping (TSA) ?
Little_man
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: [Module] pbPDF-Module

Post by Little_man »

Very nice Module.

Would you be able to give a small example of how to properly use PDF::ImageMemory with PNG image

Little_man
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Module] pbPDF-Module

Post by Paul »

Little_man wrote: Tue May 18, 2021 7:27 am Very nice Module.

Would you be able to give a small example of how to properly use PDF::ImageMemory with PNG image

Little_man
Apparently doesn't work
https://www.purebasic.fr/english/viewto ... 81#p540281
Image Image
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

Save this file in pdf/examples folder.
It loads "PureBasic.png" into memory encodes image and adds it to page. I used format "pdf::#Image_PNG".
it works with PB 5.73LTSx64 win10x64

Code: Select all


XIncludeFile "..\pbPDFModule.pbi"

Define LinkID.i, File$ = "pbPDF-imageMemory.pdf"
Define *pdf_1_mem,pdf_1_img,pdf_1_size
#PDF = 1

If PDF::Create(#PDF)
  
  PDF::AddPage(#PDF)
  
  LinkID = PDF::AddLinkURL(#PDF, "https://www.purebasic.com/")
  
  pdf_1_img = LoadImage(#PB_Any,"PureBasic.png");#PB_Any
  If pdf_1_img                                  ; if there was an image in that location
    *pdf_1_mem=EncodeImage(pdf_1_img,#PB_ImagePlugin_PNG);
    If *pdf_1_mem
      pdf_1_size= MemorySize(*pdf_1_mem)
      ;pdf::ImageMemory(ID.i, ImageName.s, *Memory, Size.i, Format.i, X.f=#PB_Default, Y.f=#PB_Default, Width.f=#PB_Default, Height.f=#PB_Default, Link.i=#NoLink)
      pdf::imagememory(#pdf,"PureBasic.png",*pdf_1_mem,pdf_1_size,pdf::#Image_PNG,20,20,60,20,LinkID)
      ; PDF::Image(#PDF, "PureBasic.png", 10,  20, 30, 10, LinkID)  
    EndIf     
    FreeMemory(*pdf_1_mem)
    FreeImage(pdf_1_img)
  EndIf
  PDF::Close(#PDF, File$)
EndIf

RunProgram(File$)
Norm
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Module] pbPDF-Module

Post by Paul »

Thanks Norm !!
That would have been really handy a year and a half ago :P
Image Image
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: [Module] pbPDF-Module

Post by normeus »

Paul,

The "Notify when reply is posted" never worked for me. hopefully it has been fixed with the new board. I was just lucky that I saw @Little_man's post and your reply today. ( actually, I got an email notice about your reply to my post, so it does work ) :lol: :wink:

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Little_man
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: [Module] pbPDF-Module

Post by Little_man »

 
Thanks for the information, 'Norm'' !!

Little_man
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 »

Hello at all
Excuse by advance this stupid question :oops: , but is it possible to simply open and show an existing PDF ? with this splendid module 8)
ImageThe happiness is a road...
Not a destination
Post Reply