f.rizzo3
f.rizzo3

Reputation: 13

PDFsharp bitmap size

I'm using PDFsharp library to transform a control into a PDF file. The problem is that the bitmap image, even if I set height and width and the format is A4, does not fill the view in Adobe Reader.
I also tried to set the parameters manually from DPI but it does not work. The script is:

 Dim docum As New PdfDocument()
    For i As Integer = 0 To FoglioFattura1.listaPagIndex.Count - 1
        Dim memImage = New Bitmap(FoglioFattura1.Width, FoglioFattura1.Height) 'A4Size
        FoglioFattura1.DrawToBitmap(memImage, New Rectangle(0, 0, FoglioFattura1.Width, FoglioFattura1.Height))

        Dim oPage As New PdfPage()
        oPage.Orientation = PageOrientation.Portrait
        oPage.Size = PageSize.A4
        'oPage.TrimMargins.Left = 30
        'oPage.TrimMargins.Top = 50
        docum.Pages.Add(oPage)

        Dim xgr As XGraphics = XGraphics.FromPdfPage(oPage)
        Dim img As XImage = XImage.FromGdiPlusImage(memImage)
        xgr.DrawImage(img, 0, 0)
        Next

These are the dimensions of the document, I have hidden the content for privacy reasons. I want the document fill the view.

enter image description here

Upvotes: 1

Views: 407

Answers (1)

The problem is that you call DrawImage without specifying the destination size of the image in the PDF. Add Width and Height to the DrawImage call and the image will be drawn in the size you specify.

PDFs have no DPI. The size if the PDF page is given in Points - and Points are not pixels.
See also:
https://en.wikipedia.org/wiki/Point_(typography)

Upvotes: 1

Related Questions