com.openhtmltopdf.objects.pdf.MergeBackgroundPdfDrawer Maven / Gradle / Ivy
package com.openhtmltopdf.objects.pdf;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.io.RandomAccessBuffer;
import org.apache.pdfbox.multipdf.LayerUtility;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.util.Charsets;
import org.w3c.dom.Element;
import com.openhtmltopdf.extend.FSObjectDrawer;
import com.openhtmltopdf.extend.OutputDevice;
import com.openhtmltopdf.pdfboxout.PdfBoxOutputDevice;
import com.openhtmltopdf.render.RenderingContext;
public class MergeBackgroundPdfDrawer implements FSObjectDrawer {
private final Map>> formMap = new HashMap>>();
@Override
public Map drawObject(Element e, double x, double y, double width, double height,
OutputDevice outputDevice, RenderingContext ctx, int dotsPerPixel) {
/*
* We can only do something if this is a PDF.
*/
if (!(outputDevice instanceof PdfBoxOutputDevice))
return null;
String pdfsrc = e.getAttribute("pdfsrc");
String pdfpageValue = e.getAttribute("pdfpage");
if (pdfpageValue == null || pdfpageValue.isEmpty())
pdfpageValue = "1";
int pdfpage = Integer.parseInt(pdfpageValue);
PdfBoxOutputDevice pdfBoxOutputDevice = (PdfBoxOutputDevice) outputDevice;
String url = ctx.getUac().resolveURI(pdfsrc);
SoftReference