#1 2014-06-20 17:20:18

Kent
Member
Registered: 2014-06-19
Posts: 4

Setting Page Height

I got the sample PDF file working. However, I need to be able to change the height of the page based upon the document that I am creating. This page may be as long as 50 inches in length. When changing the height of the page in the example program all printing disappears from the page. Here is the code I am using:

      lPdf.ScreenLogPixels:=600;

      lPage := lPDF.AddPage;
      lPage.PageHeight := lPdf.ScreenLogPixels * 50;  // This is the added line. If I remove this everything is displayed on the page.
      lPdf.VCLCanvas.Brush.Style:=bsClear;
      MyY:=300;
      for MyX := 1 to 40  do begin
         MyXLoc:=(MyX*120)  mod lPage.PageWidth;
         MyString:=IntToStr(MyX);
         lPDF.VCLCanvas.TextOut(MyXLoc, MyY, Mystring);    
         lPDF.VCLCanvas.Font.Size:= lPDF.VCLCanvas.Font.Size+4;
         lPDF.VCLCanvas.Rectangle(MyXLoc, MyY, MyXLoc+lPDF.VCLCanvas.TextWidth(MyString), MyY+lPDF.VCLCanvas.TextHeight(MyString));
         MyY := MyY + lPDF.VCLCanvas.TextHeight(MyString);
      end;
      lPdf.SaveToFile('c:\Syntest.pdf');

Offline

#2 2014-06-20 19:51:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,235
Website

Re: Setting Page Height

PageHeight is to be set before calling the AddPage method.

Set DefaultPageWidth / DefaultPageHeight before AddPage.

Online

#3 2014-06-21 13:20:31

Kent
Member
Registered: 2014-06-19
Posts: 4

Re: Setting Page Height

If I move the setting of page height/width before calling AddPage I get a run time error stating that lPage is not initialized. How do I create the page?

Offline

#4 2014-06-24 20:56:17

Kent
Member
Registered: 2014-06-19
Posts: 4

Re: Setting Page Height

I want the document to have 600 DPI and to be 8 inches wide x 50 inches long. This is what I currently have. Nothing is printed on the page.

   lPdf := TPdfDocumentGDI.Create;
   try
     lPdf.ScreenLogPixels:=600;

      lPdf.DefaultPageHeight := lPdf.ScreenLogPixels * 50;   // Since ScreenLogPixels holds the number of pixels per inch this should give me a 50 inch long page.
      lPdf.DefaultPageWidth := lPdf.ScreenLogPixels * 8;     // Same here with Page being 8 inches wide.
                                                                                    // When viewing the document in Adobe Reader the page height and width 66.67 x 200.00 with nothing displayed
                                                                        // If I comment out the ScreenLogPixels line the page size becomes 10.67 x 66.67 with a pixel count of 768 x 4800 with the proper text on the document. 
      lPage := lPDF.AddPage;
      lPdf.VCLCanvas.Brush.Style:=bsClear;
      MyY:=300;
      lPDF.VCLCanvas.TextOut(100, 100, 'Width = ' + IntToStr(lPage.PageWidth) +
            ' Height = ' + IntToStr(lPage.PageHeight));
      for MyX := 1 to 400  do begin
         MyXLoc:=(MyX*120) mod (lPage.PageWidth);
         MyString:=IntToStr(MyX);
         lPDF.VCLCanvas.TextOut(MyXLoc, MyY, Mystring);
         lPDF.VCLCanvas.Font.Size:= lPDF.VCLCanvas.Font.Size+4;
         lPDF.VCLCanvas.Rectangle(MyXLoc, MyY, MyXLoc+lPDF.VCLCanvas.TextWidth(MyString), MyY+lPDF.VCLCanvas.TextHeight(MyString));
         MyY := MyY + lPDF.VCLCanvas.TextHeight(MyString);
      end;
      lPdf.SaveToFile('c:\Syntest.pdf');
   finally
      lPdf.Free;

   end;

Last edited by Kent (2014-06-24 20:58:46)

Offline

#5 2014-06-24 21:21:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,235
Website

Re: Setting Page Height

Instead of DefaultPageHeight, which uses PDF size and not screenlogplixels, you could use DefaultPaperSize property instead.
Technically, PDF has no resolution. Images are made of samples and can be scaled to nearly any size.

For dimensions, see the setter method:

const PAPERSIZE: array[TPDFPaperSize] of array[0..1] of integer =
  ( (595,842), (419,595), (842,1190), (612,792), (612,1008), (0,0) );
begin // psA4, psA5, psA3, psLetter, psLegal, psUserDefined

The VCL TCanvas drawing uses diverse coordinates system:

  fVCLCanvasSize.cx := MulDiv(PageWidth,FDoc.FScreenLogPixels,72);
  fVCLCanvasSize.cy := MulDiv(PageHeight,FDoc.FScreenLogPixels,72);

as stated by TPdfPageGDI.SetVCLCurrentMetaFile.

Online

#6 2014-06-25 16:38:03

Kent
Member
Registered: 2014-06-19
Posts: 4

Re: Setting Page Height

I am sorry I don't understand what you are saying. Can you change the above code to work? Thanks for your help.

Offline

#7 2014-06-25 21:17:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,235
Website

Re: Setting Page Height

In raw PDF, all locations and sizes are stored in a logical value called a PDF unit. 1 PDF unit is equivalent to 1/72 of an inch.

DefaultPageHeight and DefaultPageWidth are values in PDF units, so 1/72th of a inch.

So for a 50' * 8' page, you can write:

 lPdf.DefaultPageHeight := 72 * 50; 
 lPdf.DefaultPageWidth := 72 * 8;     

Then the VCL canvas available in lPdf.VCLCanvas will have a diverse coordinate system, depending in fact of lPdf.ScreenLogPixels.

So when you draw something in the lPdf.VCLCanvas, ensure you use the right size for coordinates, i.e. via lPdf.VCLCanvasSize values.

Online

Board footer

Powered by FluxBB