|
Rank: Newbie Groups: Member
Joined: 4/3/2014 Posts: 3
|
Hi, I have an jpg file which is 1600 * 2121 96dpi. i need to convert this to a pdf file. I'm using the code below, this is working ok, but the resulting pdf is A4 size en shows aproximatly a quarter of the source jpg. (the left bottom part) when a select the image in the pdf it seems that the whole image is there as the selection covers an area 4 times as big.
question: how can i make sure the image fits in the pdf, or the pdf scales to the size of the image?
thanks in advance
CODE:
string inputFile = @"c:\image.jpg"; string newFileName = @"c:\image.pdf";
PdfDocument doc = new PdfDocument(); PdfPage page = new PdfPage(); System.Drawing.Image image = System.Drawing.Image.FromFile(inputFile);
EO.Pdf.Drawing.PdfImage pdfImage = new EO.Pdf.Drawing.PdfImage(inputFile);
EO.Pdf.Contents.PdfImageContent content = new EO.Pdf.Contents.PdfImageContent(pdfImage); content.AutoScale(); content.GfxMatrix.Translate(0, 0);
doc.Pages.Add(page); page.Contents.Add(content);
doc.Save(newFileName);
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, If you wish to change the paper size, you can just set the PdfPage's Size property. If you wish the scale the image differently so that it fits the paper, you would call content.GfxMatrix.Scale instead of content.AutoScale. See here for more details: http://www.essentialobjects.com/doc/4/acm/pdf%20content%20api/image.aspxThanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/3/2014 Posts: 3
|
Hi, thanks for the quick response. I tried changing size by using the code below, but whatever i do, size is always 8.5 - 11?
PdfDocument doc = new PdfDocument(); PdfPage page = new PdfPage(); page.Size.Width = PdfPageSizes.A3.Width; page.Size.Height = PdfPageSizes.A3.Height; System.Drawing.Image image = System.Drawing.Image.FromFile(inputFile);
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, I think you must set it as a whole:
Code: C#
page.Size = new PdfSize(w, h);
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/3/2014 Posts: 3
|
thanks, that works!
also you're other sugestion is also working:
content.GfxMatrix.Scale((float)612, (float)792);
thanks alot!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Glad to hear that it works for you. Please feel free to let us know if you have any more questions.
Thanks!
|
|