I’m using Aspose.Pdf for .Net and I’m having an issue with getting the image to be sized correctly for the pdf. I want to take a jpg and convert it to an exact same sized pdf file.
Hi Connor,
//
Create Document instance<o:p></o:p>
Aspose.Pdf.Document doc = new Document();
// add page to pages collection of document instance
doc.Pages.Add();
Aspose.Pdf.Image image = new Aspose.Pdf.Image();
// create Bitmap image so we can get image information
Bitmap bitmap = new Bitmap("c:/pdftest/-logo.png");
image.File = "c:/pdftest/logo.png";
// add image to pagaraphs collection of first page
doc.Pages[1].Paragraphs.Add(image);
// set height of first page equal to image height
doc.Pages[1].PageInfo.Height = bitmap.Height;
// set widht of first page equal to image width
doc.Pages[1].PageInfo.Width = bitmap.Width;
// trip margin around all corners of page
doc.Pages[1].PageInfo.Margin.Left = 1;
doc.Pages[1].PageInfo.Margin.Top = 1;
doc.Pages[1].PageInfo.Margin.Bottom = 1;
doc.Pages[1].PageInfo.Margin.Right = 1;
// save the PDF document
doc.Save("c:/pdftest/Image_to_PDF.pdf");
Thank you this seemed to fix the issue. Also I’m curious if there is a way to rotate the pdf image to portrait? Wondering specifically about Aspose.PDF.
Hi Connor,
// Create Document instance<o:p></o:p>
Aspose.Pdf.Document doc = new Document();
// add page to pages collection of document instance
doc.Pages.Add();
Aspose.Pdf.Image image = new Aspose.Pdf.Image();
// create Bitmap image so we can get image information
Bitmap bitmap = new Bitmap("c:/pdftest/PDF_A_1b_Compliance-Test.PNG");
image.File = "c:/pdftest/PDF_A_1b_Compliance-Test.PNG";
// add image to pagaraphs collection of first page
doc.Pages[1].Paragraphs.Add(image);
// set height of first page equal to image height
doc.Pages[1].PageInfo.Height = bitmap.Height;
// set widht of first page equal to image width
doc.Pages[1].PageInfo.Width = bitmap.Width;
// trip margin around all corners of page
doc.Pages[1].PageInfo.Margin.Left = 1;
doc.Pages[1].PageInfo.Margin.Top = 1;
doc.Pages[1].PageInfo.Margin.Bottom = 1;
doc.Pages[1].PageInfo.Margin.Right = 1;
MemoryStream ms = new MemoryStream();
// save the PDF document
doc.Save(ms);
Aspose.Pdf.Document temp_doc = new Document(ms);
temp_doc.Pages[1].Rotate = Rotation.on90;
temp_doc.Save("c:/pdftest/Image_to_PDF.pdf");
ms.Close();
Is there a way to check to see which orientation it is in?
Hi Connor,connork:Is there a way to check to see which orientation it is in?We would only like to rotate if it is in landscape and also want to make sure we don’t flip the image upside down.