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 Oct 31, 2016 3:22 pm

Hi, I'm triying to create a docx document and save it into memoryStream for not save on server, and after generate a pdf from that memorystream. In mi IIS this code work perfectly but on Azure server no.

Document docpdf = new Document();

using (MemoryStream stream = new MemoryStream())
{
document.SaveToStream(stream, Spire.Doc.FileFormat.Docx);
docpdf.LoadFromStream(stream, Spire.Doc.FileFormat.Docx);

stream.Flush();
stream.Close();
}

using (MemoryStream pdfstream = new MemoryStream())
{
docpdf.SaveToStream(pdfstream, Spire.Doc.FileFormat.PDF);
Response.Clear();

if (Context.Response.IsClientConnected)
{
//Context.Response.AppendHeader("Content-Type:", "application/pdf");
Context.Response.ContentType = "application/pdf";
Context.Response.OutputStream.Write(pdfstream.ToArray(), 0, pdfstream.ToArray().Length);
Context.Response.Flush();
}

pdfstream.Flush();
pdfstream.Close();
}


The error that server is reporting are:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, String description) +225161
System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type) +34
spr1448.0(PageSetup A_0, ImageType A_1, MemoryStream A_2, Int32 A_3, GraphicsUnit A_4) +258
spr1448.0(PageSetup A_0, ImageType A_1, MemoryStream A_2, Int32 A_3) +19
spr1448.20() +224
spr1448.1(IDocument A_0) +235
spr746.0(Document A_0) +93
Spire.Doc.Document.0(Stream A_0) +97
Spire.Doc.Document.SaveToFile(Stream stream, FileFormat fileFormat) +287
Spire.Doc.Document.SaveToStream(Stream stream, FileFormat fileFormat) +47
System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678


If I comment this line: docpdf.SaveToStream(pdfstream, Spire.Doc.FileFormat.PDF); there isn't any problem but the navigator now show pdf visor whit error of document because the memory stream is in .docx format.

[email protected]
 
Posts: 15
Joined: Wed Aug 24, 2016 7:10 am

Tue Nov 01, 2016 3:10 am

Hi,

Thanks for your inquiry.
Please try to use following code to convert word file to PDF on Azure server.
Code: Select all
            Document doc = new Document();
            string resultname = "result.pdf";
            doc.LoadFromFile(filename);
            ToPdfParameterList tpl = new ToPdfParameterList
            {
                UsePSCoversion = true//azure
            };
            doc.SaveToFile(resultname, tpl);

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Fri Nov 04, 2016 8:04 am

Hi,

Did you test the solution I provided ? Has your issue been resolved ?

Thanks,
Betsy
E-iceblue support team
User avatar

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

Wed Nov 09, 2016 10:40 am

Sorry but i have to find other solution for time problems, If have a oportunity to try your code, I will reply

[email protected]
 
Posts: 15
Joined: Wed Aug 24, 2016 7:10 am

Thu Nov 10, 2016 9:01 am

Hi, I have tried your sample code, but when I create the variable ToPdfParameterList I dont have the option UsePSCoversion = true//azure, you can see the next link to see image whit the options I have.

https://drive.google.com/open?id=0B53XE2ec9woRd0o4VUFhdGQzamc

[email protected]
 
Posts: 15
Joined: Wed Aug 24, 2016 7:10 am

Thu Nov 10, 2016 9:08 am

Hi,

Thanks for the information.
Please try to use the latest Spire.Doc Pack(hot fix) Version:5.8.13, which has that function.
If there is any qeustion, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Fri Nov 18, 2016 8:59 am

Hi,

Did you test the version I mentioned ? Has the issue been resolved ?

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Thu Dec 15, 2016 7:17 am

Hi Betsy,

Can you provide more information on the 'UsePSCoversion' property? If I use it am I able to perform conversions to pdf within Azure App Service? If so, are there any drawbacks or tradeoffs?


Thanks,
Brad

isource
 
Posts: 4
Joined: Wed Jun 24, 2015 2:09 am

Thu Dec 15, 2016 7:57 am

Hi Brad,

Thanks for your inquiry.
If use 'UsePSCoversion' property, it will not use GDI when converting.
Sorry that we don't full test the property on Azure App Service, so I am afraid that we cannot give you more information of drawbacks or tradeoffs.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Fri Dec 16, 2016 5:04 am

Hi Betsy, thanks for the quick reply.

OK, that is interesting. If it works well in Azure App Service it would simplify my target environment and deployments. At the moment I need a separate Azure Cloud service to host my pdf conversion functionality.


Cheers,
Brad

isource
 
Posts: 4
Joined: Wed Jun 24, 2015 2:09 am

Fri Dec 16, 2016 5:36 am

Hi Brad,

Thanks for your response.
If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Fri Dec 16, 2016 7:34 am

Hi Betsy,

Is the non-gdi conversion functionality only available for docs, or can it also used for other file types, for example spreadsheets and presentations?


Thanks,
Brad

isource
 
Posts: 4
Joined: Wed Jun 24, 2015 2:09 am

Fri Dec 16, 2016 7:40 am

Also, the following code throws a generic error in GDI+ when executed in an Azure WebJob:

Code: Select all
public class DocumentConverter : IFileConverter
    {
        private static object _lockObject = new object();

        public Stream ConvertToPdf(Stream file)
        {
            var document = new Document();
            var result = new MemoryStream();

            document.LoadFromStream(file, FileFormat.Auto);

            var tpl = new ToPdfParameterList
            {
                UsePSCoversion = true
            };

            lock (_lockObject)
            {
                document.SaveToStream(result, tpl);
            }

            return result;
        }
    }


Thanks,
Brad

isource
 
Posts: 4
Joined: Wed Jun 24, 2015 2:09 am

Fri Dec 16, 2016 7:49 am

Dear Brad,

Thanks for the feedback.
Sorry that at present the non-gdi function is only available in Spire.Doc.
And sorry that it still throw a generic error in GDI+ when executed in an Azure WebJob, I am afraid currently there is no other way to avoid this error.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.PDF