First of all thanks for a great product, I didn't realize creating PDFs could be so easy, and mirroring .NET classes like drawing make conversion SOOOOO easy...
But I'm having an issue, not a software bug, but a me not knowing what I'm doing bug.
Here is what I'm doing:
Create an XForm, 2400x3150 pixels
Draw an image onto the XForm, same size as the XForm, at 0,0
Add a page, width/height same as the xform
Draw the xform onto the page at 0,0
Draw text/images/etc onto the page
Add page to a document
Now, it all works, however the output is roughly 75% of the size it should be. I think this is a 72 DPI/96 DPI conversion issue. When I define the form I create it as xunit.frompoint, and I use pixels everywhere.
I'm trying to just load a background image, then draw stuff at specific x/y coordinates on the pages. I can get it to work by dividing the page size and all my coordinates by 1.25, but that seems kinda silly and I think I'm just not getting something here.
So I guess my question is what is the relationship between the size of an XForm, a page defined as the same size, and drawing things onto the page at specific locations. I want to get rid of all my "
/ SizeMod" snippets of code and better understand how to create PDFs.
I'm also not real sure how I should define all my margins, though I have been fudging it by just drawing the stuff at particular offsets. Setting a margin and then using 0,0 as my drawing offset instead of 50,50 or whatever would also be helpful.
And a last thing, my pages are like 90% white space, but still nearly 1mb in size due to the size of the background graphic (its a frame basically), any way to decrease that?
Thanks in advance.
Here is my code (Sorry its in VB.NET, {} give me a headache, and VB.NET has yet to show me a limitation):
Code:
'Create Document
Dim PDF_Doc As New PdfSharp.Pdf.PdfDocument
Dim PDF_Font As New PdfSharp.Drawing.XFont("Arial", 16)
'Create a new bitmap from a 2400 x 3150 pixel file
Dim BMP As New Bitmap("C:\Temp_Background.png")
'Create the background form
Dim PDF_Form As New PdfSharp.Drawing.XForm(PDF_Doc, 2400, 3150) 'PdfSharp.Drawing.XUnit.FromPoint(2400), PdfSharp.Drawing.XUnit.FromPoint(3150))
'Draw image onto background form
Dim FormGfx As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromForm(PDF_Form)
FormGfx.DrawImage(BMP, 0, 0)
'A divider I have to use in order for the pages to render correctly
Dim SizeMod As Single = 1.25
'Create new page
Dim Page As New PdfSharp.Pdf.PdfPage(PDF_Doc)
Page.Size = PdfSharp.PageSize.A4
Page.Width = 2400 / SizeMod
Page.Height = 3150 / SizeMod
'Draw background form onto page
Dim Gfx As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(Page)
Gfx.DrawImage(PDF_Form, 0, 0, 2400, 3150)
'Create outline/bookmark for this page
Dim PDF_Outline As New PdfSharp.Pdf.PdfOutline("Page1", Page)
PDF_Doc.Outlines.Add(PDF_Outline)
'Load up an image to draw onto the page
Dim TempBMP As Bitmap = Bitmap.FromFile("C:\Temp_Image.png")
TempBMP.MakeTransparent(TempBMP.GetPixel(0, 0))
'Draw the image onto the page
Gfx.DrawImage(TempBMP, 930 / SizeMod, 650 / SizeMod, 626 / SizeMod, 811 / SizeMod)
'Draw some text on page, I'm giving a 50 pixel border on top/left, though I'm not sure this is the best method
Gfx.DrawString("Page 1", PDF_Font, PdfSharp.Drawing.XBrushes.Red, New PdfSharp.Drawing.XPoint((50 + 27) / SizeMod, (50 + 764) / SizeMod))
'Add to document
PDF_Doc.AddPage(Page)
PDF_Doc.Close()
PDF_Doc.Save("C:\PDFTest.pdf")