Free Support Forum - aspose.com

Problem getting image to the full size of the page

Due to some problems with pptx to pdf support right now I am creating thumbnails of the pptx and wanting to place them in a pdf file. I have been unsuccessful of getting the image to show up full size on the page with no border or margin.


Here is the code:

Pdf pdf = new Pdf();
var marginInfo = new MarginInfo();
marginInfo.Bottom = 0;
marginInfo.Left = 0;
marginInfo.Right = 0;
marginInfo.Top = 0;
pdf.PageSetup.Margin = marginInfo;
foreach (var bmp in listBmp)
{
var section = new Section(pdf);
section.IsLandscape = true;

Aspose.Pdf.Image image = new Aspose.Pdf.Image(section);
image.ImageScale = .5F;
image.Margin = marginInfo;
image.ImageHeight = bmp.Height;
image.ImageWidth = bmp.Width;

image.ImageInfo.ImageFileType = ImageFileType.Bmp;
image.ImageInfo.ImageStream = BitmapToStream(bmp);

image.ImageInfo.Title = String.Empty;
var border = new BorderInfo(0);
image.ImageInfo.Alignment = AlignmentType.FullJustify;
image.ImageInfo.ImageBorder = border;
section.Paragraphs.Add(image);
pdf.Sections.Add(section);
}

Hello Eric,

Thanks for considering Aspose.

Please try using the following code snippet to accomplish your requirement. The following code reads the image files (JPEG) in a particular folder and converts them into a single PDF document, where the size of the image is same as the PDF size (no margin and border at any side).

[C#]

Pdf pdf = new Pdf();

MarginInfo marginInfo = new MarginInfo();
marginInfo.Bottom = 0;
marginInfo.Left = 0;
marginInfo.Right = 0;
marginInfo.Top = 0;
pdf.PageSetup.Margin = marginInfo;

Aspose.Pdf.Section section = pdf.Sections.Add();

string[] fileEntries = Directory.GetFiles(@"D:\pdftest\tempforImages\", "*.jpg");

for(int i=0; i<fileEntries.Length; i++)
{
section.IsLandscape = true;

Aspose.Pdf.Image image = new Aspose.Pdf.Image(section);
image.Margin = marginInfo;
image.ImageInfo.FixHeight= section.PageInfo.PageHeight;
image.ImageInfo.FixWidth= section.PageInfo.PageWidth;
image.ImageInfo.ImageFileType = ImageFileType.Jpeg;
image.ImageInfo.File = fileEntries[i];

section.Paragraphs.Add(image);
}

pdf.Save(@"D:\pdftest\tempforImages\sampleresultant.pdf");

In case it does not satisfy your requirements or you've any further query, please feel free to contact.