Logo
My Account |  Site Map | Contact Us  
Welcome Guest Search | Active Topics | Sign In | Register

PdfDocument.Merge exception Options
Mercell
Posted: Tuesday, March 5, 2019 5:29:59 AM
Rank: Newbie
Groups: Member

Joined: 8/18/2016
Posts: 3
We have an internal webservice to merge PDFs and it has been running for years. Now we have two specific files that EO cannot merge and save.

Code: C#
PdfDocument doc1 = new PdfDocument(stream1);
PdfDocument doc2 = new PdfDocument(stream2);
PdfDocument mergedDoc = PdfDocument.Merge(doc1, doc2);
using (MemoryStream ms = new MemoryStream())
{
	mergedDoc.Standard = pdfStandard;
	mergedDoc.Save(ms); // EXCEPTION !!!
	return ms.ToArray();
}


I've called save on the two docs to dump the PDFs and contents seems to be okay.

The exception is:

Quote:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at EO.Pdf.Drawing.PdfImage..ctor(vx A_0)
at EO.Pdf.Drawing.PdfImage.a(vx A_0, Int32 A_1)
at EO.Internal.gh.b(a5c A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.kn.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.a72.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.a72.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.kn.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.a72.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.kn.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.ok.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.a72.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.kn.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.a72.a(awk A_0)
at EO.Internal.al.c(a5c A_0)
at EO.Internal.al.a(a5c A_0)
at EO.Internal.gh.a(Boolean A_0, Boolean A_1)
at EO.Pdf.PdfDocument.Save(Stream stream)
...


In production we are using EO 18.3.23 on Windows Server 2016 Datacenter, and error reproduced on my developer PC with latest version of EO 19.0.69 from NuGet on Windows 10.
eo_support
Posted: Tuesday, March 5, 2019 8:04:35 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,094
Hi,

It appears that one of the source file contains an image that we can not read. This usually is not a problem if you are not trying to convert to PDFA, however in case of PDFA, we must add a white background (otherwise it will default to a black background) to the image and that appears to be failing. You can try to save the content of the input stream to a file and then send both files to us. Once we have that we will look into it and see why it fails. If it's an invalid or unsupported image format, then we may need to ignore the image or skipping adding background so that the merge would still complete. See here for how to send test files to us:

https://www.essentialobjects.com/forum/test_project.aspx

Thanks!
Mercell
Posted: Tuesday, March 5, 2019 9:32:26 AM
Rank: Newbie
Groups: Member

Joined: 8/18/2016
Posts: 3
Unfortunately, we cannot send you the PDFs as it contain information about the customer. We are working on to recreate the issue using test data. Until then, I can see that the second document is from HtmlToPdf where the HTML looks something like (some data and tags removed)

Code: HTML/ASPX
<tr>
	<td class="icon">
		<a href="/m/file/GetFile.ashx?id=1234&amp;version=1">
			<img class="vIcon24" src="/m/file/getFileIcon.ashx?ext=doc">
		</a>
	</td>
	<td class="icon">
		<a href="/m/file/GetFile.ashx?id=1234&amp;version=1" title="download">
			<svg aria-label="Download" class="vIcon24">
				<use xlink:href="#Download">
					<svg viewBox="0 0 24 24" id="Download" width="100%" height="100%">
						<polyline ...></polyline>
						<path ...></path>
						<line ...></line>
					</svg>
				</use>
			</svg>
		</a>
	</td>
</tr>


The above page is rendered by HtmlToPdf and if I dump the file I can open the PDF in Acrobat Reader!

Are you aware of any limitations when using SVG?
eo_support
Posted: Sunday, March 10, 2019 11:37:20 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,094
Hi,

Sorry about the delay. We have been trying to reproduce the issue in our environment but have not been successful.

The issue does not really have anything to do with SVG. The root of the issue is a transparent bitmap image in the PDF file that we can not load successfully. Usually when the HTML to PDF converter renders a SVG image, it does not generate a bitmap at all because SVG is in vector format and many SVG element can be translated into vector drawing instructions natively supported by PDF format. However sometimes this may not be possible and in that case the SVG will be rasterized and a bitmap will be generated and embedded in the PDF file. When this bitmap is transparent (which would be the case for a SVG without a solid background), this transparent background will be replaced with a solid white background when the result file is saved in PDF/A since PDF/A does not allow transparency. This last step requires us to read the bitmap which is failing in your case. This bitmap in question can be generated by/from anything, not necessarily from SVG. Such image would not be a problem when you do not save in PDF/A format because the image will just stay as is.

We have been trying to craft SVG with transparent background but with elements that would force it to be rasterized (such as another transparent bitmap image overlayed with other SVG elements), however both our converter and the merger worked fine with our test files. So if you managed to reproduce the issue, please send to us and we will be happy to investigate further.

Thanks
eo_support
Posted: Friday, March 15, 2019 10:41:19 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,094
Hi,

This is just to let you know that we have looked into the files you sent to us and found the root of the problem. This issue will be resolved in our next build. We will reply here again when the build is available.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.