Print Page | Close Window

DrawCapturedPage and "AutoRotation"

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=2071
Printed Date: 29 Sep 24 at 3:20AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: DrawCapturedPage and "AutoRotation"
Posted By: twaldorff
Subject: DrawCapturedPage and "AutoRotation"
Date Posted: 15 Dec 11 at 11:14AM
Hi
I'm using version 8.12
I'm using the CapturePage-DrawCapturedPage functions to insert pages from an other pdf in a report while preserving report header/footer.
I have got the process working OK, but there is something I don't understand:
 
My main report is in A4 portrait and contains a number of blank pages (except for header/footer) reserved for the other pdf. The other report is in A4 landscape.
Using plain DrawCapturedPage works OK, where I would have expected having to use DrawCapturedPageEx to include rotation information, but that is apparently not required.
 
Is this an "AutoRotation" feature? Or is there something else at play?
 
Thomas



Replies:
Posted By: edvoigt
Date Posted: 23 Dec 11 at 2:52PM
Hi Thomas,

please explain what you want. I understand only, that there is a PDF1 in A4 portrait, which has pages with a free area for pages from PDF2, which are A4 landscape. What is the goal? Clear is, you want to get a Page of PDF2 in smaller size on a reserved page of PDF1. What automatism do you expect or really get?

Want you while drawing PDF2-Page onto a Page of PDF1 leave the orientation as is or not?

Please show a code snippet and the both used PDFs to answer your question.

Cheers,

Werner


Posted By: twaldorff
Date Posted: 31 Dec 11 at 2:58PM
Hi Werner
 
I'm not trying achieve something beyond an explanation.
From a PDF point-of-view I'm getting what I want to get.
My "problem" is that I don't understand why I get it.
 
You have understood the basic input OK.
First I attach the landscape PDF to the main portrait PDF. (qp.merge)
Stopping here and looking into the file, the pages show in portrait and landscape as expected.
 
Then I capturepage/drawcapturedpage taking a landscape page and superimposing it on a portrait page. I'm not doing any scaling or rotating in this process.
 
In this situation this is fine, the landscape page is "autorotated", but why?
 
That is the question,
 
Thomas


Posted By: edvoigt
Date Posted: 31 Dec 11 at 4:04PM
Hi Thomas,

I'm rather sure, that there is any kind of rotate-command in one of your PDFs. Here is my test, which shows what with normal PDFs happens:

var
  pid: integer;
  pw, ph: double;
begin
  QP := TQuickPDF.Create;
  QP.UnlockKey({$I PDFkey.inc});
  QP.NewDocument;
  QP.SetMeasurementUnits(1);
  QP.SetOrigin(0);
  QP.SetPageDimensions(210, 297);
  QP.DrawText(25, 250, 'Portrait-Page');
  QP.SetLineColor(0, 0, 1);            // blue
  QP.SetLineWidth(1);
  QP.DrawBox(1, 296, 208, 295, 0);     // borderline
  QP.SaveToFile('PDF1_Portrait.pdf');

  QP.NewDocument;
  QP.SetMeasurementUnits(1);
  QP.SetOrigin(0);
  QP.SetPageDimensions(297, 210);
  QP.DrawText(150, 100, 'Landscape-Page');
  QP.SetLineColor(1, 0, 0);            // red
  QP.SetLineWidth(1);
  QP.DrawBox(1, 209, 295, 208, 0);    
// borderline
  QP.SaveToFile('PDF2_Landscape.pdf');

  QP.Free; // to forget all, no sideeffects possible

  QP := TQuickPDF.Create;
  QP.UnlockKey({$I PDFkey.inc});
  QP.MergeFiles('PDF1_Portrait.pdf', 'PDF2_Landscape.pdf', 'PDF_mixed.pdf');

  // now the imposition
  QP.LoadFromFile('PDF_mixed.pdf', '');
  QP.SelectPage(2);
  pw := QP.PageWidth;          // after capture we can't ask for this
  ph := QP.PageHeight;
  pid := QP.CapturePage(2);    // get the landscape-page

  QP.SelectPage(1);            // the page where we want to put the captured page down
  QP.DrawCapturedPage(pid, 0, ph, pw, ph); // without scaling the landscape is clipped
  QP.SaveToFile('PDF_done.pdf');
  QP.Free;


Because I was thinking in this direction, I did ask for the PDFs, you are using. In them is anything disturbing you.

More if needed next year.

Cheers,
Werner


Posted By: twaldorff
Date Posted: 01 Jan 12 at 12:21PM
Hi Werner
 
Happy new year and thanks for responding.
The behaviour you describe is the one I would have expected.
 
Since the forum does not allow me to upload files I have stored a zip-file here
http://ge.tt/9eLsxnB - http://ge.tt/9eLsxnB
The file contains main1.pdf and appe1.pdf
The files are NOT created by QuickPDF but by a PDF printer (Bluebeam) from Word and Excel respectively.
 
They are used by the following example demonstrating my point
 
 
procedure superimpose;
var
 QP: TQuickPDF0813;
 UnlockResult: Integer;
 unlockkey: String;
 FileA: integer;
 FileB: integer;
 CapturedPageID: integer;
 PageHeight: Double;
 PageWidth: Double;
begin
  qp := TQuickPDF0813.Create;
  unlockkey := 'whatever';
  try
    begin
      UnlockResult := qp.UnlockKey(unlockkey);
      if UnlockResult = 1 then
        begin
          If qp.LoadFromFile('main1.pdf', '') = 1 Then
            begin
              FileA := qp.SelectedDocument;
              PageHeight := qp.PageHeight;
              PageWidth := qp.PageWidth;
              If qp.LoadFromFile('appe1.pdf', '') = 1 Then
                begin
                  FileB := qp.SelectedDocument;
                  qp.SelectDocument(FileA);
                  qp.MergeDocument(FileB);
 
                  qp.SaveToFile('tmp.pdf');
                 // In this file you will se the two page in portrait and landscape respectively.
 
                  CapturedPageID := qp.CapturePage(2);
                  qp.SelectPage(1);
                  qp.DrawCapturedPage(CapturedPageID, 0, PageHeight, PageWidth, PageHeight);
                End;
              qp.SaveToFile('main1_final.pdf');
            end;
        end
     else
        begin
          ShowMessage('Invalid license key');
        end;
    end;
  finally
    qp.Free;
  end;
end;
Please give it a try and see if you experience the same as I do.
 
Thomas
 


Posted By: edvoigt
Date Posted: 01 Jan 12 at 3:55PM
Hi Thomas,

we are on the right way. As I did guess, in the landscape-PDF is one /Rotate-command in the object, which describes the contents of the PDF.

But step by step to understand the problem. A first search for Mediabox shows:

/MediaBox[0 0 595.22 842]

that is a A4-portrait in points. Therefore the PDF is primary build as portrait. To bring it in the wished landscape-orientation, there is a few bytes later this:

... >>/Rotate 90/Type/Page>>

If you use a good editor like notepad++ change it carefully (don't change the length of anything and beware all binarys as they are):

... >>/Rotate 00/Type/Page>>

Proof: In this form Adobe Reader shows it as portrait, as it really is.

Anyway there goes the rotate lost during capture, thats because subject of the rotation seems to be a page, but if we draw it as captured, it becomes to be a part of a page , what means no own rotation. Then it is drawn as constructed - portrait. So I think about this, explaining the automatic. It may be good and it may disturb, depending on the PDF-Quality.

We may bring all in correct state with a short code:

var
  rotation: integer;
...
  rotation := QP.PageRotation; // the page of interest has to be selected
  if (rotation<>0)
  then begin
    QP.DrawText(1,150, Format('Rotation %d',[rotation])); // only to see this as test
    QP.RotatePage(rotation);             // realize the defined rotation
  end;
  pw := QP.PageWidth;          // after capture we can't ask for this
  ph := QP.PageHeight;
  pid := QP.CapturePage(...    // the now rotated sourcepage


With asking for the rotation we get informed about the build in rotation-statement. With RotatePage this is really performed, then we get the better formed PDF and get the correct values for pagedimensions. Read for this carefully the QP-ReferenceGuide at p. 508.

With the value of rotation and the relation between pagewith and pageheight, you should be able to handle all PDFs as you want and draw them with the right rotation-value.


Cheers,

Werner


Posted By: twaldorff
Date Posted: 01 Jan 12 at 8:13PM
Hi Werner
 
Thank you very much for the elaborate explanation, and also for directing me to the commands required to handle this issue in a more generic fashion.
 
Thanks again
Thomas



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