Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Feb 12, 2018 4:27 pm

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

Galina.Lapson
 
Posts: 2
Joined: Fri Jan 26, 2018 8:50 pm

Tue Feb 13, 2018 3:31 am

Dear Galina,

Thanks for your inquiry.
After an initial testing, I am unable to reproduce your issue on my side. First we suggest upgrading to the latest Spire.Office Platinum (DLL Only) Version:2.16.27 which includes all fixes. If your issue still happens after try the latest version, please provide your input image and result PDF for further investigation. You could send it to us([email protected]) via email.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Feb 13, 2018 6:51 pm

Have you tested in a free community edition conversion of a .JPG file to PDF if the original file size is greater 1MB? If yes, and it works, can you please share the code in C#. I am attaching a sample file.

I am using your online sample code (article "Convert Image to PDF in C#, VB.NET"), it doesn't say there are any file size limitations. Now, I tested many files. It only works if the file size less 1MB. Otheriwse, there is no error message but Acrobat can not open the file. At this point I am not interested in upgrading to a commercial version.

Hope you can help.
Thank you
Galina

Galina.Lapson
 
Posts: 2
Joined: Fri Jan 26, 2018 8:50 pm

Wed Feb 14, 2018 2:22 am

Dear Galina,

Thanks for your sharing.
I tested your case with the Free Spire.Office and indeed found the issue you mentioned. But I'm sorry to tell you that we have no plan to maintain the free version at present. However, I confirmed that your issue didn't occur in the Free Spire.PDF for .NET Version:3.2. Please download this version to have a try. If there is any question, welcome to write back.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF