basic help to generate pdf file

kaushik

New Member
Hi to all ,
I m new in webspeed ,i want to know basic steps to develope a program which gives it output to field .i mean i want to give output of a report to pdf.
suppose i hv to give output of item table to pdf .
kindly suggest me a site where i can learm abt pdf function ,procedure .

thanks
 

kolonuk

Member
If you run on linux, you should be able to output to a stream pointing to a file, then run

Code:
UNIX VALUE("enscript -f Helvetica10 -p report.ps report.txt").
UNIX VALUE("ps2pdf report.ps report.pdf").

There may be windows versions of those linux programs, but then you might be able to install a pdf printer (primoPDF?) and direct the text file to that...

But, for a more integrated solution and more, yes, try the OEHive...
 

CyrixInstead

New Member
I would use PDFInclude (see http://www.oehive.org/pdfinclude) to create a temporary PDF file on the web server, read that in and output through the Webstream.

For example, output to a temporary file name:
Code:
ASSIGN cFilePDF = OS-GETENV("temp":U) + "/temporary_filename.pdf".
RUN pdf_new("Spdf",cFilePDF).
/* Continue building PDF */
After the pdf has been created by PDFInclude read it in and output to the webstream. In my example the variable cFilePDF is the name that the PDF sent to the user's browser will be called:
Code:
DEFINE VARIABLE rwFileLine AS RAW        NO-UNDO.

/* Output HTTP headers prior to running. Use the Output-Content-Type() function
to output the proper header based on the file type. For instance to output
a .gif file, you would use output-content-type("image/gif").
A fully qualified path is required.

/* This will open the PDF in the user's browser */
output-http-header ("Content-disposition","Inline~;filename=" + cFileOut).
/* You would use the following to open the save dialog */
/*output-http-header ("Content-disposition","Attachment~;filename=" + cFileOut).*/

/* Must use the Binary qualifier here to prevent code page
   tanslations on the way in. */

INPUT STREAM infile FROM VALUE(cFilePDF) BINARY NO-ECHO NO-MAP NO-CONVERT.

/* Read the file in 1024 byte chunks.  Input must be UNFORMATTED
   in order to read the binary codes. Output directly to the
   browser using the WEBSTREAM pre-processor. PUT must also
   use CONTROL to prevent code page translations on the way out. */

REPEAT:
    LENGTH(rwFileLine) = 1024.
    IMPORT STREAM infile UNFORMATTED rwFileLine.
    PUT {&WEBSTREAM} CONTROL rwFileLine.
END.

/* Clean-up: Raw variable should be reset to deallocate the memory, the stream
             should be closed and the temporary PDF deleted. */

LENGTH(rwFileLine) = 0.
INPUT STREAM infile CLOSE.
OS-DELETE VALUE(cFilePDF) NO-ERROR.
I hope that helps.

~Cyrix
 

Cecil

19+ years progress programming and still learning.
Hi. Another choice is to use wkhtml2pdf (very similar to PrinceXML). wkhtml2pdf has the added advantage to run Javascript. I know this is more than you require but if you wanted to produce an a "High Quality" chart, then use HighCharts. HighCharts will dynamically rendered a chart from data from your database and display it in your Internet Browser (IE, FF, CHROME, etc).

This is what I've started using myself. My design requirement was to produce an online report which managers could "Drill Down" (there words not mine) and then produce a PDF document which included a Cover Page, Table of Contents, Headers & Footers.

Using WebSpeed I was able to produce the web report and generate the PDF document using the same webspeed code. No need to write separate code for web and one for PDF, it's all the same.

The reason I am using wkhtml2pdf are:

  1. It's free. GNU General Public License v3
  2. Reusable code for both Web and PDF
  3. Headers and footers are automatically inserted for each page of the PDF
  4. Automatically can generate a Table of Contents at the start of the PDF Document.
  5. I can include charts rendered by HighCharts which can be displayed in the PDF as PDF Vector Graphic rather than bitmap image.
  6. The wkhtml2pdf project is very active with new releases every few months.
  7. Good support from the project's forum.
  8. The latest version now correctly handles page breaks and a content being broken up as it spans across two pages.

How does wkhtml2pdf work. wkhtml2pdf for starters is cross platform compatible (Linux, Windows, MacOS). You simply run wkhtml2pdf from the command line (i.e. from WebSpeed OS-COMMAND statement) and passes the URL of your HTML report and pass a second parameter of the name of the Outputted PDF file. Then using CyrixInstead
code, upload the newly created PDF file. Done.

Before anyone berates me for advertising I have no affiliation with HighCharts and/or wkthml2pdf. These are just products which I am using internally for my own projects and they work and works really well for my company's requirements.
 
Top