Welcome Guest Search | Active Topics | Sign In | Register

Transparent images on pdf/a files has black background Options
santtuv
Posted: Monday, August 7, 2017 9:53:05 AM
Rank: Newbie
Groups: Member

Joined: 8/7/2017
Posts: 4
Hi,

When converting from HTML to PDF/A, transparent images has black background. Is this a bug or is there some setting that can fix it?

Here is code example that I'm using.

Code: C#
EO.Pdf.HtmlToPdfOptions opt = new EO.Pdf.HtmlToPdfOptions();
opt.PageSize = EO.Pdf.PdfPageSizes.A4;
opt.AutoFitX = EO.Pdf.HtmlToPdfAutoFitMode.ScaleToFit;
opt.AutoFitY = EO.Pdf.HtmlToPdfAutoFitMode.ScaleToFit;
EO.Pdf.PdfDocument doc = new EO.Pdf.PdfDocument();
doc.Standard = EO.Pdf.PdfStandard.PDF_A;

EO.Pdf.HtmlToPdf.ConvertUrl("(some url)", doc, opt);
doc.Save(txtOutputPdf.Text);


Here is example image when converting to PDF (everything is ok)

If image isn't embedded, please click here


Here is example image when converting to PDF/A

If image isn't embedded, please click here
eo_support
Posted: Monday, August 7, 2017 9:58:27 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

This behavior is by design. Transparency is disabled on purpose for PDF/A because we support PDF/A-1, which does not allow transparency.

Thanks!
santtuv
Posted: Monday, August 7, 2017 10:03:37 AM
Rank: Newbie
Groups: Member

Joined: 8/7/2017
Posts: 4
Thanks for super fast reply. So there's no way to change the background color from black to white? EO.PDF seems very good product for our client, but I think that this would be showstopper. Requirement is to convert HTML pages to PDF/A to be saved to archive.
eo_support
Posted: Monday, August 7, 2017 10:21:33 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
There is no easy way to do that. Our converter did not add the black background --- we just tells the PDF that this is a PDF-A file. The PDF Viewer application then sees that aplha channel is not permitted on the image and it then renders the background as black. Another PDF Viewer may decide to show a purple background for this case. Since the black background is not added by us, we have no control over that part.

There is one way to workaround this but it is not easy. It would require you to implement your own custom resource handler to convert the image with transparency to image with solid background (you would then add white background in this case). Instead of using simple calls like HtmlToPdf.ConvertUrl, you would need to use this method:

https://www.essentialobjects.com/doc/eo.pdf.htmltopdfsession.runwebviewcallback.aspx

The code would be something like this:

Code: C#
//Register your own custom resource handler and load the Url
session.RunWebViewCallback((WebView webView, object args) =>
{
    webView.RegisterResourceHandler(your_custom_handler);

    webView.LoadUrlAndWait(your_url);
}, null);

//Perform the conversion
session.RenderAsPDF(pdf_file_name);

//Unregister the custom resource handler
session.RunWebViewCallback((WebView webView, object args) =>
{
    webView.UnregisterResourceHandler(your_custom_handler);
}, null);


Here custom resource handler is an advanced EO.WebBrowser feature that allows you to intercept any HTTP request made by the browser engine and handle it your own way. This is where you would write code to:

1. Fetch the image from the server (for example, you can use .NET's built-in WebRequest class to do that);
2. Post process the image you received to add white background and remove transparency;
3. Pass the modified image down to the browser engine;

You can find more information about custom resource handler here:

https://www.essentialobjects.com/doc/webbrowser/advanced/resource_handler.aspx

Please let us know if you have any question implementing this.

Thanks!
santtuv
Posted: Wednesday, August 9, 2017 6:18:42 AM
Rank: Newbie
Groups: Member

Joined: 8/7/2017
Posts: 4
Thanks, I managed to create working custom handler and got white background images instead of black background.

However generated PDF isn't PDF/A compliant. Should I start another topic on this?

When checked with Adobe Acrobat Preflight tool (PDF/A1-a or PDF/A1-b) following errors are listed:

1. Structured PDF: Structure tree root entry missing
2. Trasparency used (filled object with ca value smaller than 1.0)
3. Text cannot be mapped to Unicode
4. Width information for rendered glyph is inconsistent


Code I used to create PDF/A document.

Code: C#
EO.Pdf.HtmlToPdfOptions opt = new EO.Pdf.HtmlToPdfOptions();
            opt.UserName = txtDomain.Text + "\\" + txtUser.Text;
            opt.Password = txtPwd.Text;
            string[] headers = new string[1];
            headers[0] = "Accepted-Language:fi-FI";
            opt.AdditionalHeaders = headers;
            using (HtmlToPdfSession session = HtmlToPdfSession.Create(opt))
            {
                ImageHandler handler = new ImageHandler();

                session.RunWebViewCallback((WebView webView, object args) =>
                {
                    webView.RegisterResourceHandler(handler);
                    Request request = new Request(txtUrl.Text);
                    webView.LoadRequestAndWait(request);
                    return null;
                }, null);

                EO.Pdf.PdfDocument doc = new EO.Pdf.PdfDocument();
                doc.Standard = PdfStandard.PDF_A;
                session.RenderAsPDF(doc);

                doc.Save(txtOutputPdf.Text);
                session.RunWebViewCallback((WebView webView, object args) =>
                {
                    webView.UnregisterResourceHandler(handler);
                    return null;
                }, null);
            }
eo_support
Posted: Thursday, August 10, 2017 2:52:17 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

We will look into this and see what we can find.

Thanks!
eo_support
Posted: Wednesday, August 16, 2017 10:54:07 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

We have looked into this issue and we have fixed issue #1 and #2. However we can not reproduce issue #3 and #4 here (it may have to do with the files you are converting or has to do with issue#1 and #2). Can you PM us the Url that you are trying to convert so that we can check on our end?

The fix for #1 and #2 will be included in our next build.

Thanks!
eo_support
Posted: Thursday, September 14, 2017 9:57:29 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

We have posted a new build that should fix #1 and #2. You can download it from our download page and take a look.

Issue #3 and #4 has to do with the font you use in your style. The root of the problem is that your page uses a woff font instead of a TrueType font. The woff font file you use does not contain the necessary information to correctly generate information that would satisfy #3 and #4. Switching to true type font should resolve these two issues for you. We will reply your private message with more details on this issue.

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.