Welcome Guest Search | Active Topics | Sign In | Register

generate pdf from large jpeg file Options
Netwinst Finance
Posted: Thursday, April 3, 2014 5:15:58 PM
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);
eo_support
Posted: Thursday, April 3, 2014 5:25:31 PM
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.aspx

Thanks!
Netwinst Finance
Posted: Thursday, April 3, 2014 5:36:56 PM
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);
eo_support
Posted: Thursday, April 3, 2014 5:46:21 PM
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!

Netwinst Finance
Posted: Thursday, April 3, 2014 5:53:16 PM
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!
eo_support
Posted: Thursday, April 3, 2014 6:18:16 PM
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!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.