wPDF page/drawing size issue in .NET

  • Hi. I searching PDF component for my client, and wPDF GDI+ Graphics support is exactly what we need to integrate it to our code nearly without any effort!
    But seems that any on pdf becomed little bigger, so my form not fits to page.
    Page size - 8.5x11in.
    PageUnit - millimeters.[/img]

  • Code:

    public Bitmap GetPageBitMap(int DPI, PixelFormat pf, int PageNumber)
    {
    Bitmap bmp =
    new Bitmap(
    (int)(Pages[PageNumber].PageSettings.PaperSize.Width/100F*DPI),
    (int)(Pages[PageNumber].PageSettings.PaperSize.Height/100F*DPI),
    pf);
    bmp.SetResolution(DPI,DPI);

    Graphics g = Graphics.FromImage(bmp);

    g.PageUnit = GraphicsUnit.Millimeter;

    g.FillRectangle(Brushes.White, 0F, 0F,
    Pages[PageNumber].PageSettings.PaperSize.Width/100F/0.0393700787F,
    Pages[PageNumber].PageSettings.PaperSize.Height/100F/0.0393700787F);

    PrnPage(g, Pages[PageNumber].Controls, 0, 0,
    Pages[PageNumber].PageSettings.PaperSize.Width/100F/0.0393700787F,
    Pages[PageNumber].PageSettings.PaperSize.Height/100F/0.0393700787F
    );

    g.Dispose();

    return bmp;
    }

    public void GetPDF(Stream pdfstream)
    {
    PDFControl pdf = new PDFControl();
    pdf.BeginDoc(pdfstream);

    for (int PageNumber=0;PageNumber<Pages.Length;PageNumber++)
    {
    pdf.StartPage();
    pdf.Canvas.PageUnit = GraphicsUnit.Millimeter;
    PrnPage(pdf.Canvas, Pages[PageNumber].Controls, 0, 0,
    Pages[PageNumber].PageSettings.PaperSize.Width/100F/0.0393700787F,
    Pages[PageNumber].PageSettings.PaperSize.Height/100F/0.0393700787F
    );
    pdf.EndPage();
    }
    pdf.EndDoc();
    pdf.Dispose();
    }

  • Also looks like Graphics.DrawRectangle works little differen than GDI+

    Pen p = new Pen(LineColor,LineWidth);
    p.DashStyle = LineStyle;

    g.DrawRectangle(p, dx+LineWidth/2, dy+LineWidth/2, RectangleWidth, RectangleHeight);

    Set width big enoug - you see Width/2 error on starting/ending lines.

    • Offizieller Beitrag

    Hi,

    the PDF conversion engine has to work with EMF, not EMF+ data records. So it cannot work with GDI+ but use the compatibility mode. (The problem is that the EMF+ format is not documented)

    I used this code for testing:

    Code
    xDPI := Round(pdfControl1.Canvas.DpiX);  yDPI := Round(pdfControl1.Canvas.DpiY);  left :=   Trunc(0 * xDPI);  right :=  Trunc(8.5 * xDPI);  top :=    Trunc(0 * yDPI);  bottom := Trunc(11 * yDPI);   pdfControl1.Canvas.DrawLine(      System.Drawing.SystemPens.WindowText,      0,0,      right, bottom      );   pdfControl1.Canvas.DrawLine(      System.Drawing.SystemPens.WindowText,      right,0,      0, bottom      );

    but that uses the pixel PageUnit.

    I made a test with mm or ScaleTransform - that worked good:

    Julian Ziersch

  • I've got you point.
    But helped this:

    pdf.StartPage(ePage.Letter, Pages[PageNumber].PageSettings.Landscape);

    Zitat

    pdf.Canvas.ScaleTransform(1/0.0393700787F/72F*2.54F,1/0.0393700787F/72F*2.54F);


    PrnPage(pdf.Canvas, Pages[PageNumber].Controls, 0, 0,
    Pages[PageNumber].PageSettings.PaperSize.Width/100F/0.0393700787F,
    Pages[PageNumber].PageSettings.PaperSize.Height/100F/0.0393700787F
    );
    pdf.EndPage();

    But still all object's still little "bigger". May be i must take instead more precise of just 2.54.

    What about DrawRectngle issue? I can draw rect. by hand, but may be this solvable.