Print Page | Close Window

Convert Text Reports to PDFs

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: General Discussion
Forum Description: Discussion board for Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=398
Printed Date: 19 May 24 at 2:46PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Convert Text Reports to PDFs
Posted By: jabaltie
Subject: Convert Text Reports to PDFs
Date Posted: 25 Apr 06 at 8:12AM
We have here on our installation a whole constelation of Reports which are generated by a Unisys mainframe.

These reports are typically text files, whith these characteristics :

- Lines are separated by CRLF pairs (chr 13/10)
- Pages are separated by a FF (chr 12)
- Lines usually have 80 or 132 characters
- Pages typically have 66 or 88 lines
- They're printed using fixed width font size
- Reports have usually 100 pages, so conversion perfomance is not a problem, at first

My plan is to build a conversion tool, to stuff or wrap those reports onto PDF files, and then, ask my users not to print them anymore. Instead, they should convert their reports to PDF (using this tool) and save the PDF files.

Only when needed, they would print the report from the PDF file.

The report is already available on a plain text file. Although it was generated on a mainframe, it has been downloaded to a text file.

It's also available, that is, I know BEFORE converting :

- The number of characters per line (80 or 132)
- The maximum number of lines on a page (66 or 88)
- The total number of pages

So, finally :

Would someone help me out with a scheleton of a VBScript for this conversion tool ?

Other features I have in mind are :

- At first, I would not care about bookmarks but, adding a bookmark for each page could be a good idea
- Some special reports are intended to be printed on special paper. For instance papers who have a logotype already printed. So, another good idea would be to "merge" the report on a "background paper", that is, put the page "over" an image (of the paper).

After all,

Thank you !



Replies:
Posted By: swb1
Date Posted: 25 Apr 06 at 9:53AM

I am currently doing something like this. I start with a blank 8½ x 11 PDFas a template. I load the logo then I draw the text. Page breaks are determined by line count or CHR(12) - which ever comes first. You will need to experiment a little with font and line height. When the page is full, use NewPage to begin the next page then load the logo and text and so on.

 

I could supply some sample source however it would be Delphi as I don’t speak fluent VB.

 

sb



Posted By: jabaltie
Date Posted: 25 Apr 06 at 10:15AM
It could be in Delphi anyway.

All I need is some sort of kick-start code.

Thank you for your help !


Posted By: swb1
Date Posted: 25 Apr 06 at 10:58AM

This should get you started:

 

procedure TForm1.btnOverlayTextClick(Sender: TObject);

var   sl : TStringList;

      LogoName, pdfName, TextName, OutputName : string;

      i, LineIndex, ImageID : integer;

const

      MAX_LINES = 66;

      LINE_HEIGHT =15;

begin

 

      TextName := ExtractFilePath(Application.ExeName) + 'SampleInvoice.txt';

      pdfName := ExtractFilePath(Application.ExeName) + 'EmptyPage.pdf';

      LogoName := ExtractFilePath(Application.ExeName) + 'logo.jpg';

      OutputName := ExtractFilePath(Application.ExeName) + 'Output.pdf';

 

 

      if (FileExists(pdfName) and FileExists(TextName) and FileExists(LogoName) ) then

            begin

                  try

                  sl := TStringList.Create;

                  sl.LoadFromFile(TextName);

                  qPDF := TiSEDQuickPDF.Create;

                  qPDF.UnlockKey( MY_QDPF_KEY );

                  qPDF.LoadFromFile( pdfName );

                  ImageID := qPDF.AddImageFromFile( LogoName,0 );

                  qPDF.SetOrigin(1); // upper Left

 

                  Lineindex := 0;

                  for i := 0 to sl.Count -1 do

                        begin

                        if LineIndex = 0 then

                              begin

                              qPDF.SelectImage( ImageID );

                              qPDF.DrawImage(10,5,150,100);

                              end;

                        qPDF.DrawText(10, LineIndex  * LINE_HEIGHT, sl[LineIndex]);

                        if (pos(#12,sl[LineIndex]) > 0) or (LineIndex >= MAX_LINES) then

                              begin

                              if LineIndex < (sl.Count - 1) then

                                    qPDF.SelectPage(qPDF.NewPage);

                              LineIndex := 0;

                              end

                        else begin

                              LineIndex := Lineindex + 1;

                              end;

                        end;

                  qPdf.SaveToFile(OutputName);

                  finally

                        qPDF.Free;

                        sl.Free;

                  end;

            end;

 

end;




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk