Hello, when i try to convert images (Photoshop, tiff, jpg, bmp, etc) into PDF, i obtain some black borders in pdf pages.
How can i use all pdf page to occupy entire page space for image?
(see attached image originale and pdf resulting - password for pdf is “master”)
i use this code:
MemoryStream oMTempStream = new MemoryStream();
Aspose.Imaging.ImageOptions.PngOptions OptionsI = new Aspose.Imaging.ImageOptions.PngOptions();
((Aspose.Imaging.Image)m_oDocument).Save(oMTempStream, OptionsI);
Aspose.Pdf.Generator.Pdf oPdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section oSection = new Aspose.Pdf.Generator.Section();
oSection.PageInfo.Margin.Bottom = 0;
oSection.PageInfo.PageBorderMargin.Bottom = 0;
if (((Aspose.Imaging.Image)m_oDocument).Width > ((Aspose.Imaging.Image)m_oDocument).Height)
{
oPdf.IsLandscape = true;
float iW =oSection.PageInfo.PageWidth;
float iH = oSection.PageInfo.PageHeight;
oSection.PageInfo.PageWidth = iH;
oSection.PageInfo.PageHeight = iW;
}
oPdf.Sections.Add(oSection);
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(oPdf.Sections[0]);
image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png;
oPdf.Sections[0].Paragraphs.Add(image1);
image1.ImageInfo.ImageStream = oMTempStream;
oPdf.Save(_oOutputStream);
oMTempStream.Dispose();
Hi there,
string outFile =
myDir + “imagetopdfDOM.pdf”;<o:p></o:p>
string inFile = myDir + "sample4_l.jpg";
Document doc = new Document();
Page page = doc.Pages.Add();
FileStream fs = new FileStream(inFile, FileMode.Open, FileAccess.Read);
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));
MemoryStream mystream = new MemoryStream(tmpBytes);
Bitmap b = new Bitmap(mystream);
// Set margins so image will fit, etc.
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.MediaBox = new Aspose.Pdf.Rectangle(0,0,b.Width,b.Height);
page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);
//Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
//Add the image into paragraphs collection of the section
page.Paragraphs.Add(image1);
image1.File = inFile;
doc.Save(outFile);
Please feel free to contact us for any further assistance.
Best Regards,