Print Page | Close Window

Draw Text onto Existing PDF

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=714
Printed Date: 16 May 24 at 2:41AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Draw Text onto Existing PDF
Posted By: Tim Hayes
Subject: Draw Text onto Existing PDF
Date Posted: 26 Apr 07 at 9:51AM
Hi,
 
I am new to QuickPDF.
 
I am seeking to be able to add using  (for instance) page numbers to a PDF that has already been created from a scanner utility. I am using the DRAWTEXT command.
 
I have tested the command on a new document and it works fine (unlock is done).
 
On my scanned PDF, the printed output is not visible.
 
However, I have used FinePrintFactory Pro to print the PDF to another PDF file, and now I can DRAWTEXT and the result is visible.
 
There is no difference in the permissions settings between the files. The only visible differences are (a) the original is A4, the other Letter and (b) the original is 859kb long and the new PDF is 1253kb long - suggesting that there is a compression issue.
 
I am probably doing something really stupid. Any suggestions would be most helpful.
 
Many thanks
Tim Hayes
 
 
 
 



Replies:
Posted By: marian_pascalau
Date Posted: 26 Apr 07 at 11:43AM
Tim, for debug purpose you should prepare a small demo and send it to support(at)quickpdf.org
 
Or at least you should post the piece of code who writes the page numbers.


Posted By: Tim Hayes
Date Posted: 26 Apr 07 at 12:21PM
Marian
 
Newcomer apologies.
 
I have sent you a sample project with test files.
 
The code I am using is as follows:
 
procedure Tqpdf01.btExecClick(Sender: TObject);
var QPDox : TiSEDQuickPDF;
    i : integer;
begin
// 1st try with the scanned PDF
  QPDox := TiSEDQuickPDF.Create;
  try
    screen.Cursor := crhourglass;
    QPDox.UnlockKey('as needed');
    QPDox.LoadFromFile(ExtractFilePath(ParamStr(0)) + '\Test_Scan.pdf');
    with QPdox do begin
      for i := 1 to PageCount
        do begin
        SelectPage(i);
        DrawText(500, 100, 'Page : ' + inttostr(i));
        end;
      SaveToFile(ExtractFilePath(ParamStr(0)) + '\Test_Scan_Out.pdf');
// this does not work
    end;
  finally
    QPDox.Free;
    screen.Cursor := crdefault;
  end;
// now try with the reprinted PDF
  QPDox := TiSEDQuickPDF.Create;
  try
    screen.Cursor := crhourglass;
    QPDox.UnlockKey('as needed');
    QPDox.LoadFromFile(ExtractFilePath(ParamStr(0)) + '\Test_ScanNew.pdf');
    with QPdox do begin
      for i := 1 to PageCount
        do begin
        SelectPage(i);
        DrawText(500, 100, 'Page : ' + inttostr(i));
        end;
      SaveToFile(ExtractFilePath(ParamStr(0)) + '\Test_ScanNew_Out.pdf');
// this works
    end;
  finally
    QPDox.Free;
    screen.Cursor := crdefault;
  end;
end;
 
Thanks
Tim Hayes


Posted By: Ingo
Date Posted: 27 Apr 07 at 2:26AM
Hi Tim!

Perhaps it have to do with the fix output position...
Letter is different from A4 - Is "500, 100" for both okay?
Are there rotated pages?
You should use SetMeasurementUnits and SetOrigin before Drawing.

Best regards,
Ingo



Posted By: marian_pascalau
Date Posted: 27 Apr 07 at 8:12AM

Hi Tim,

I have checked your problem. The difference between the two files is caused by the fact that one of the document alter the page coordinate system and when you believe to paint something on 500/100 you realy paint somewhere else.

 

This is not so bad if you know what is happening. For you I have a solution. In your sample program you need to add 2x lines of code:

 

        QPDox.LoadFromFile(ExtractFilePath(ParamStr(0)) + '\Test_Scan.pdf');

        // <Marian note=”avoid creation of additional layer”>

        //     By default QuickPDF will add a so called

        //     safe layer which create additional content stream.

        //     Because we want to modify the original content we

        //     don’t need this feature.

        QPDox.UseUnsafeLayers(1);

        // </Marian>

        with QPdox do

        begin

            for i := 1 to PageCount do

            begin

                SelectPage (i);

                // <Marian note=”save&restore canvas status”>

                SetPageContent('q'#13#10 + // save canvas status

                    Trim(GetPageContent) + // previous content

                    #13#10'Q'#13#10);      // restore canvas status

                // </Marian>

                DrawText(500, 100, 'Page : ' + inttostr(i));

                // now this should work as well :-)

            end;

            SaveToFile(ExtractFilePath(ParamStr(0)) + '\Test_Scan_Out.pdf');

            // this does not work

        end;



Posted By: Tim Hayes
Date Posted: 27 Apr 07 at 12:05PM
Hi Marian,
 
That works really well! Thankyou. I am not sure how one gets to find these things - are there a variety of "settings" (see Ingo's note above) that should be used when opening and working with existing PDF's?
 
I really appreciate the work that you, Ingo and others are doing to support QuickPDF. I have read all there is to read on the "disappearance" of the author/owner - I do hope he or she reappears soon!
 
However, in the meantime, I am committed to embedding QuickPDF in a new product I am building. I am new to the product, but along the way, what can I do to help? 
 
I am happy to start writing some extended "how to use / what its all about" documentation as I go along. Of course I may need to ask some questions.
 
I am also happy to contribute code - for instance (although I have not yet delved into it) I see that the CPP version of ZLib is used. I have a Pascal translation that works very well, and would be willing to contribute it if there is a requirement.
 
Let me know how I can help.
 
Regards
Tim Hayes
 
 



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