#1 2011-11-28 16:19:29

betoneto.tbo
Member
From: Brasil
Registered: 2011-05-10
Posts: 29

Margin and RenderMetafile

Hi.

I need to render a Metafile using canvas.RenderMetafile at position x:0, y:0.

After do this, a got Margins at the resulting pdf.

How can I force the PDF to have NO MARGINS ?

Offline

#2 2011-11-28 16:46:23

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

Re: Margin and RenderMetafile

How are you creating your renderning?

If you use SQlite3Pages, you'll have margins by default.

But if you use directly the TSynPdf class, you won't have any margin.

1. What is your code?
2. Are you sure you do not set any margin when printing the pdf (Acrobat Reader may add margins at printing)?

Offline

#3 2011-11-28 17:02:28

betoneto.tbo
Member
From: Brasil
Registered: 2011-05-10
Posts: 29

Re: Margin and RenderMetafile

This is my code:

with TPdfDocumentGDI.Create do
      try
        UseUniscribe := True;

        CompressionMethod := cmFlateDecode;
        ScreenLogPixels := 72;

        NewDoc;

        page := TMetafile.Create;
        try
          for i := 1 to GraphicReport.PageCount do
          begin
            GraphicReport.DrawPage(i,  page); // this this the METAFILE generated by my ReportGenerator

            with AddPage do
            begin
              PageWidth := Max(PageWidth, page.Width + (MARGIN * 2));
              PageHeight := Max(PageHeight, page.Height + (MARGIN * 2));

              Canvas.RenderMetaFile(page, 1, 0, 0, False);
            end;
          end;
        finally
          page.Free;
        end;

        SaveToStream(Stream);
      finally
        Free;
      end;


After the export, the PDF has rendered my metafile out of the pdf page. the OffsetY seems not being respected.

More curious still is the following ...

The more I increase the offsetY (200, 300, 400 ...) the top margin decreases instead of increasing.

Offline

#4 2011-11-28 17:13:21

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

Re: Margin and RenderMetafile

Are you using the latest version from the source code repository?

You are mixing points and mm when setting PageWidth/PageHeight.
Note also that PDF coordinates are not working the same as GDI coordinates: they are bottom-left based.

What about leaving the page size by default?

Offline

#5 2011-11-28 18:03:11

betoneto.tbo
Member
From: Brasil
Registered: 2011-05-10
Posts: 29

Re: Margin and RenderMetafile

I solved the problem.

I noticed the following:
Change the page size causes the problem. I had to use the DefaultPageWidth and DefaultPageHeight.

And thanks about the tip:
  "Note also that PDF coordinates are not working the same as GDI coordinates: they are bottom-left based."

Please, make tests changing the page size to smaller and bigger  pages.


I think there is any problem related to changing the page size.

Try to make a PDF, add a new page and decrease the size of this page. Then try to paint a metafile of the same size on this page.

Thanks.

Offline

#6 2011-11-28 18:57:31

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

Re: Margin and RenderMetafile

AFAIK the page size shall be changed before adding a page.

Offline

#7 2024-08-28 15:12:43

svnvlad
Member
Registered: 2024-08-28
Posts: 3

Re: Margin and RenderMetafile

ab wrote:

But if you use directly the TSynPdf class, you won't have any margin.

Sorry, the class TSynPdf does not exist.

Offline

Board footer

Powered by FluxBB