Print pb form as is to printer of pdf?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Print pb form as is to printer of pdf?

Post by Fangbeast »

I have a form filled with data that for aesthetic reasons I would like printed as-is to the printer or to pdf.

Does anyone know of a way to do this? Would it have to be done as an image somehow with API? (I don't know how)
Amateur Radio, D-STAR/VK3HAF
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Print pb form as is to printer of pdf?

Post by IdeasVacuum »

Hi Fang,

Using the PurePdf Lib you define the PDF Page in a similar way to the form design. I mostly use PDF like this because it's easy enough to code, the results are sharp (unlike a form screen capture), the PDF format is a good way to store what has been emailed/printed, and of course, you can print via the PDF file for great results thanks to the free Adobe Reader (which practically everyone has).

These days most people will send an email rather than a letter if possible.
http://www.purebasicpower.de/?PurePDF
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Print pb form as is to printer of pdf?

Post by Fangbeast »

Using the PurePdf Lib you define the PDF Page in a similar way to the form design.
Hmm, I have PurePDF installed (Or rather, Harkon's version of it with some stuff for TWAIN aquisition) as I am printing some stuff to pdf but it's pretty automatic and I wanted to print my setup form exactly as I see it.

6,323 lines of code in the library (!) and I am a little lost as to where to start.
I mostly use PDF like this because it's easy enough to code, the results are sharp (unlike a form
You know what you are doing:):)

You don't know which command to use to locate the pdf cursor on a page to print a string do you? I want it to look as close to the original form as possible and I know all the cursor locations of the strings and the gadget bounds.

Need an example, sorry.
Amateur Radio, D-STAR/VK3HAF
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Print pb form as is to printer of pdf?

Post by Marc56us »

Fangbeast wrote: You don't know which command to use to locate the pdf cursor on a page to print a string do you?
[...]
Need an example, sorry.

Code: Select all

; Fast sample of PurePDF usage (no full install needed)
; Base on sample provide "Tutorial01 Hello World.pdf"

; PureBasicPower: http://www.purebasicpower.de/?PurePDF
; Download latest version 
; http://www.purebasicpower.de/?download=PurePDF225_PB52X86.zip

; Extract from Zip and copy in your folder these 2 files (without path)
; - Examples\PurePDF\PurePDF.pb
; - Examples\PurePDF\PurePDF_res.pb

#PurePDF_Include=1
XIncludeFile "PurePDF.pb"

Define file$="Tutorial01 Hello World.pdf"

pdf_Create()
pdf_AddPage()
pdf_SetFont("Arial","B",16)

pdf_Cell(40,10,"Hello World!",1)

pdf_Save(file$)
RunProgram(file$)

; (Tested on PB 5.60 x64)
:wink:
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Print pb form as is to printer of pdf?

Post by Fangbeast »

Marc56us, I was just fiddling around before I came back here and saw your post.

I put a graphic banner at the top of the page (had to calculate divided by 4 to get the correct resolution for the page DPI) but when I add a cell to the page, it prints it over the image.

That's why I asked about locating the cursor where I wanted it so that it starts under the image.

Not sure I will fit my form in portrait mode anyway but I had to try to see if I could get anything started.

These figures (150/4, 25/4) are my original text gadget dimensions divided by 4 to get the correct size for the page by the way.

Code: Select all

XIncludeFile "Modules\ThirdParty\_HK_PurePDF 2_25.pbi"                                                ; Harkon's conversion of ABBKlaus's PDF creation code

#PurePDF_Include = 1

Procedure Footer()
  pdf_SetY(-15)
  pdf_SetFont("MS SansSerif", "I", 8);
  pdf_Cell(0, 10, "Page " + Str(pdf_GetPageNo()) + "/" + Chr(14), 0, 0, #PDF_ALIGN_CENTER);
EndProcedure

Procedure makePDF(run)
  Protected PDFFileName.s
  Protected String$, StringWidth.d, i
  Protected CreateBookmarks=#True
  
  PDFFileName.s = GetFilePart(#PB_Compiler_File)
  PDFFileName.s = Mid(PDFFileName.s, 1, Len(PDFFileName.s) - Len(GetExtensionPart(PDFFileName.s)) - 1)
  
  pdf_Create()
  
  pdf_SetProcFooter(@Footer())
  
  pdf_AliasNbPages(Chr(14))     ; you need this to match your Footer procedure currently chr(16)
  
  pdf_SetAuthor("Fangled beastly")
  pdf_SetTitle(PDFFileName.s)
  pdf_SetSubject("Trial MyStuff Print")
  pdf_SetCreator("PurePDF")
  pdf_SetKeywords(StringField(PDFFileName.s, 1, "Inventory"))
  
  pdf_AddPage()
  
  pdf_Image(GetCurrentDirectory() + "Images\_Other\NoPicture4.jpg", 0, 0, 210, 25) ; Puts an image in the page. Figues divided by 4
  
  pdf_SetFont("Comic Sans MS", "", 10)
  
  pdf_BookMark("Page 1a")
  
  pdf_Cell(150/4, 25/4, "", 1, 1, #PDF_ALIGN_CENTER, 0, 0)
  
  pdf_Cell(150/4, 25/4, "Name of the item", 1, 1, #PDF_ALIGN_CENTER, 0, 0)
  
  PDFFileName.s = Str(run)
  pdf_Save(PDFFileName.s   + ".pdf")
  RunProgram(PDFFileName.s + ".pdf")
EndProcedure

makepdf(2)
Amateur Radio, D-STAR/VK3HAF
Post Reply