简体   繁体   中英

Transparent images are showing up as black boxes after xfa.fillXfaForm. Are transparent images supported for the xfa fill?

Here's the current problem: I have an XFA Form created by a 3rd party and I would like to use it as is. I was able generate the PDF with filled fields by:

a) Extracting the XML via Acrobat Pro
b) filling the fields within the XML and calling 
            XfaForm xfa = form.getXfa();
            xfa.fillXfaForm(new FileInputStream(XML));

What I'm trying to do is just stamp an image/watermark over the 2nd page which has a form w/multiple fields. The "DRAFT" png image I'm stamping has a transparent background so if the overlay works, the image background should make the underlay appear and look like that the image text is sitting on top of the pdf page.

What I wanted to accomplish would have been trivial if this was not an XFA form. I would just use iText's pdfStamper and stamp this transparent PNG over the 2nd page, but since I'm now confined to use Adobe LiveCycle Designer, I noticed that this once trivial task in the non XFA document isn't so trivial within XFA. From a previous post, I learned that I couldn't mix technologies together. I had to choose between nonXFA (AcroForms) vs XFA (built by Adobe LiveCycle Designer). Basically, I couldn't do a fillXFA then use the stamper, so I had to figure out how to do this using XFA.

I've tried the following steps as a static PDF and a dynamic PDF....it didn't make a difference what type the PDF was.

1) Within Adobe LiveCycle Designer, I went to the second page of the source PDF and defined 2 image fields.

  overlay1 - this will span the top portion width of the page which has text 
             content underneath
  overlay2 - this will span the lower portion width of the page which has text 
             content underneath

2) As a test...I selected an image for overlay1 which has a transparent background and it's foreground background as DRAFT At design time...the DRAFT transparency image worked and it was laid on top of the content correctly for the imageField: overlay1. I saved the modified XFA-based PDF, opened it up in Acrobat Pro, and exported the XFA XML structure. I verified that overlay1 had the DRAFT image as a base64 encoded string.

<overlay1 xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:contentType="image/png"
>iVBORw0KGgoAAAANSUhEUgAACWAAAAJYCAYAAADmY91UAAAACXBIWXMAAC4jAAAuIwF4pT92AABH
.......
.......

3) When I took the same base 64 string and only entered it's content within overlay2 and rendered it through the fillXFA method...the image was a black box instead. I also opened the file in Acrobat Pro, then double clicked on the imageField area, selected the transparent image, and it still showed up as a black box. I repeated the previous step with an image w/no transparency and it's rectangular white background overlayed everything underneath it.

4) I went ahead and made another image...one that didn't have any transparency. DRAFT with no transparency and it's background is white. I had it encoded in base64 format. I was able to place it within both overlay1 & overlay2 image fields without any problems. The new problem is that the white background of the DRAFT images covered everything behind it.

Why did the initial transparent png work during the Adobe LifeCycle Design (design time) and after a fillXFA call it shows up as a black box? But if I change the image to not use transparency at all...everything works?

Does XFA not support transparent images for image fields during an xfa fill? Remember, it worked during design time when I told Adobe LiveCycle designer to use this transparent png for this field.

I'm basically trying to create 2 image watermarks over a specific page within an XFA pdf.

My current backup plan is to flatten the PDF (take off the XFA) and putting back all the fields back on the form using Acrobat Pro and filling it using the standard PDF itext calls and using a stamper (this is going to be tedious since there's a bunch of fields). But I'd like to know if anyone ever had to do the same w/an XFA PDF form before I look at option B.

So I replaced the same PNG transparent image with a GIF transparent image. The GIF image encoded in base64 worked. I can create a new GIF file w/transparency, encode it in base64, and replace the previous one & it still worked. Looks like a bug with PNG rendering within the XFA form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM