Acrobat Error when open PDF for big image.gif
Hi, I wonder if anyone else has a problem when converting a large image (over 1.5MB) to a PDF format? I have Windows 10, in IL/ USA. I am using community edition of Spire Office for .NET. No problem with images less than 1 MB.
It does not give an error message when converting to PDF but when I try to open the file, it won't open and Acrobat says an error exists in the file (please see attachment). I pass the image file contents as binary, convert to PDF and save in a sql server table:
using Spire.Pdf;
using Spire.Pdf.Graphics;
protected void ConvertImageToPDF(String file_name, String file_ext1, byte[] file_contents1)
{
SQLMethods sql = new SQLMethods();
string mime_type = "application/pdf";
string file_ext = ".pdf";
int pos = file_name.IndexOf('.');
file_name = file_name.Substring(0, pos) + ".pdf";
// create a PDF document with a section and page added
PdfDocument doc = new PdfDocument();
PdfSection section = doc.Sections.Add();
PdfPageBase page =doc.Pages.Add();
// load an image to PDF and set image location
using (MemoryStream ms1 = new MemoryStream(file_contents1))
{
PdfImage image = PdfImage.FromStream(ms1);
float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = image.PhysicalDimension.Width / fitRate;
float fitHeight = image.PhysicalDimension.Height/ fitRate;
page.Canvas.DrawImage(image, 30, 30, fitWidth, fitHeight);
// convert to PDF format
using (MemoryStream ms2 = new MemoryStream())
{
doc.SaveToStream(ms2);
byte[] file_contents = ms2.ToArray();
int count = sql.InsertUploadedDoc(startdate, appl_id, cust_id, file_name, file_ext, mime_type, file_contents);
}
}
}
Any suggestions highly appreciated.
Thank you
Galina
Login to view the files attached to this post.