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.
Thu Jun 18, 2020 2:32 pm
I am showing a mailmerge document converted to PDF on my website.
Would you check this code to see if this is the best way to do it please?
- Code: Select all
public ActionResult ShowPDFOnWebsite(int psfAppID)
{
var resourcePath = ReflectionUtil.GetManifestResourceStreamNameByFileName("PsfApplicationTemplate.docx");
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream1 = assembly.GetManifestResourceStream(resourcePath))
{
var data = _PsfAppReportUtil.GetModelAsDataTable(_EfContext, psfAppID);
var doc = new Spire.Doc.Document(stream1);
doc.MailMerge.HideEmptyParagraphs = true;
doc.MailMerge.Execute(data);
var stream2 = new MemoryStream();
doc.SaveToStream(stream2, Spire.Doc.FileFormat.PDF);
var pdfDoc = new PdfDocument(stream2);
pdfDoc.SaveToHttpResponse("test.pdf", System.Web.HttpContext.Current.Response, HttpReadType.Open);
return null;
}
}
-

[email protected]
-
- Posts: 110
- Joined: Tue May 19, 2015 8:09 pm
Thu Jun 18, 2020 5:09 pm
This code works in development mode, but when I deploy it to our servers in Azure I get this error.
- Code: Select all
ExternalException: A generic error occurred in GDI+.
Module "spr⣝", line 117, in ᜀ
System.Drawing.Image ᜀ(Spire.Doc.PageSetup, Spire.Doc.Documents.ImageType, System.IO.MemoryStream, Int32, System.Drawing.GraphicsUnit)
Module "spr⣝", line 242, in ᜓ
Boolean ᜓ()
Module "spr⣝", line 187, in ᜀ
spr⣴ ᜀ(Spire.Doc.Interface.IDocument)
Module "spr⤈", line 34, in ᜀ
Spire.Pdf.PdfNewDocument ᜀ(Spire.Doc.Document)
Module "Spire.Doc.Document", line 22, in ᜂ
Void ᜂ(System.IO.Stream)
...
-

[email protected]
-
- Posts: 110
- Joined: Tue May 19, 2015 8:09 pm
Thu Jun 18, 2020 7:07 pm
drawing.JPG
Found this issue with Microsoft.
Login to view the files attached to this post.
-

[email protected]
-
- Posts: 110
- Joined: Tue May 19, 2015 8:09 pm
Fri Jun 19, 2020 3:43 am
Hello,
Thanks for your inquiry.
Please try to use PS conversion method to convert Doc to PDF on Azure, as shown below. If the issue still occurs after trying, please provide a sample runnable project to help us investigate further. You could send it to us(
[email protected]) via email. Thanks in advance.
- Code: Select all
//...
var stream2 = new MemoryStream();
ToPdfParameterList tpl = new ToPdfParameterList
{
UsePSCoversion = true
};
doc.SaveToStream(stream2, tpl);
var pdfDoc = new PdfDocument(stream2);
pdfDoc.SaveToHttpResponse("test.pdf", System.Web.HttpContext.Current.Response, HttpReadType.Open);
Sincerely,
Rachel
E-iceblue support team
-


rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am
Fri Jun 19, 2020 3:02 pm
That worked great.
Thank you.
-

[email protected]
-
- Posts: 110
- Joined: Tue May 19, 2015 8:09 pm
Mon Jun 22, 2020 1:13 am
Hello,
Glad to hear that!
If you encounter any issues related to our product in the future, just feel free to contact us!
Have a nice day!
Sincerely,
Rachel
E-iceblue support team
-


rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am