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.

Tue Jul 08, 2014 1:11 am

I am using Sprite.PDF to convert PDF to images. It is working locally (purchased the component)... but on the server I am getting this error...

Any ideas?


Here is the line where the exception occurs:
var img = doc.SaveAsImage(pageCount, PdfImageType.Metafile);

(This is executing in a controller in an asp.net MVC app)

A generic error occurred in GDI+.
Source:
System.Drawing

Stack Trace:
at System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, String description)
at System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type)
at spr᫁.ᜀ(Stream A_0, Int32 A_1, Int32 A_2)
at spr᫁.ᜀ(Single A_0)
at Spire.Pdf.PdfDocumentBase.ᜀ(Stream A_0, Int32 A_1)
at Spire.Pdf.PdfDocumentBase.ᜀ(Int32 A_0, PdfImageType A_1)
at Spire.Pdf.PdfDocument.SaveAsImage(Int32 pageIndex, PdfImageType type)
at WB.Controllers.ReportController.Create(Report report, HttpPostedFileBase file)
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()

patness
 
Posts: 10
Joined: Tue Jul 08, 2014 12:15 am

Tue Jul 08, 2014 1:30 am

This error is resolved by changing this line:

doc.SaveAsImage(pageCount, PdfImageType.Metafile);

into this:

doc.SaveAsImage(pageCount, PdfImageType.Metafile, 150, 150);

(Basically, the DPI is required on the server. If not specified the error is thrown)

patness
 
Posts: 10
Joined: Tue Jul 08, 2014 12:15 am

Tue Jul 08, 2014 1:36 am

Hello,

Thanks for your sharing.
Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Dec 17, 2019 2:03 am

I'm getting the same error but using Spire.Doc to convert a docx to pdf using Document.SaveToFile(). The exception is exactly the same, but that API doesn't seem to have a way to specify the DPI for the conversion, not sure if that even applies when converting to PDF. Any ideas?

robertoandrade
 
Posts: 1
Joined: Tue Dec 17, 2019 1:59 am

Tue Dec 17, 2019 8:38 am

Hi,

Thanks for your inquiry.
Please first try to use the latest Spire.Doc Pack(hot fix) Version:7.11.1 which has more improvements than old version. If the issue still happens, please provide following information for further investigation:
1. The input Word file
2. The full code you were using
3. The type of your project, e.g. console application
4. The framework of your project, e.g. .NET4.0

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.PDF