Java Code Examples for org.apache.pdfbox.pdmodel.PDResources

The following are top voted examples for showing how to use org.apache.pdfbox.pdmodel.PDResources. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: testarea-pdfbox2   File: RenderType3Character.java   Source Code and License 9 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/42032729/render-type3-font-character-as-image-using-pdfbox">
 * Render Type3 font character as image using PDFBox
 * </a>
 * <br/>
 * <a href="https://drive.google.com/file/d/0B0f6X4SAMh2KRDJTbm4tb3E1a1U/view">
 * 4700198773.pdf
 * </a>
 * from
 * <a href="http://stackoverflow.com/questions/37754112/extract-text-with-custom-font-result-non-readble">
 * extract text with custom font result non readble
 * </a>
 * <p>
 * This test shows how one can render individual Type 3 font glyphs as bitmaps.
 * Unfortunately PDFBox out-of-the-box does not provide a class to render contents
 * of arbitrary XObjects, merely for rendering pages; thus, we simply create a page
 * with the glyph in question and render that page.   
 * </p>
 * <p>
 * As the OP did not provide a sample PDF, we simply use one from another
 * stackoverflow question. There obviously might remain issues with the
 * OP's files.
 * </p>
 */
@Test
public void testRenderSdnList() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("sdnlist.pdf"))
    {
        PDDocument document = PDDocument.load(resource);

        PDPage page = document.getPage(1);
        PDResources pageResources = page.getResources();
        COSName f1Name = COSName.getPDFName("R144");
        PDType3Font fontF1 = (PDType3Font) pageResources.getFont(f1Name);
        Map<String, Integer> f1NameToCode = fontF1.getEncoding().getNameToCodeMap();

        COSDictionary charProcsDictionary = fontF1.getCharProcs();
        for (COSName key : charProcsDictionary.keySet())
        {
            COSStream stream = (COSStream) charProcsDictionary.getDictionaryObject(key);
            PDType3CharProc charProc = new PDType3CharProc(fontF1, stream);
            PDRectangle bbox = charProc.getGlyphBBox();
            if (bbox == null)
                bbox = charProc.getBBox();
            Integer code = f1NameToCode.get(key.getName());

            if (code != null)
            {
                PDDocument charDocument = new PDDocument();
                PDPage charPage = new PDPage(bbox);
                charDocument.addPage(charPage);
                charPage.setResources(pageResources);
                PDPageContentStream charContentStream = new PDPageContentStream(charDocument, charPage);
                charContentStream.beginText();
                charContentStream.setFont(fontF1, bbox.getHeight());
                charContentStream.getOutput().write(String.format("<%2X> Tj\n", code).getBytes());
                charContentStream.endText();
                charContentStream.close();

                File result = new File(RESULT_FOLDER, String.format("sdnlist-%s-%s.png", key.getName(), code));
                PDFRenderer renderer = new PDFRenderer(charDocument);
                BufferedImage image = renderer.renderImageWithDPI(0, 96);
                ImageIO.write(image, "PNG", result);
                charDocument.save(new File(RESULT_FOLDER, String.format("sdnlist-%s-%s.pdf", key.getName(), code)));
                charDocument.close();
            }
        }
    }
}
 
Example 2
Project: testarea-pdfbox2   File: RenderType3Character.java   Source Code and License 8 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/42032729/render-type3-font-character-as-image-using-pdfbox">
 * Render Type3 font character as image using PDFBox
 * </a>
 * <br/>
 * <a href="https://drive.google.com/file/d/0B0f6X4SAMh2KRDJTbm4tb3E1a1U/view">
 * 4700198773.pdf
 * </a>
 * from
 * <a href="http://stackoverflow.com/questions/37754112/extract-text-with-custom-font-result-non-readble">
 * extract text with custom font result non readble
 * </a>
 * <p>
 * This test shows how one can render individual Type 3 font glyphs as bitmaps.
 * Unfortunately PDFBox out-of-the-box does not provide a class to render contents
 * of arbitrary XObjects, merely for rendering pages; thus, we simply create a page
 * with the glyph in question and render that page.   
 * </p>
 * <p>
 * As the OP did not provide a sample PDF, we simply use one from another
 * stackoverflow question. There obviously might remain issues with the
 * OP's files.
 * </p>
 */
@Test
public void testRender4700198773() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("4700198773.pdf"))
    {
        PDDocument document = PDDocument.load(resource);

        PDPage page = document.getPage(0);
        PDResources pageResources = page.getResources();
        COSName f1Name = COSName.getPDFName("F1");
        PDType3Font fontF1 = (PDType3Font) pageResources.getFont(f1Name);
        Map<String, Integer> f1NameToCode = fontF1.getEncoding().getNameToCodeMap();

        COSDictionary charProcsDictionary = fontF1.getCharProcs();
        for (COSName key : charProcsDictionary.keySet())
        {
            COSStream stream = (COSStream) charProcsDictionary.getDictionaryObject(key);
            PDType3CharProc charProc = new PDType3CharProc(fontF1, stream);
            PDRectangle bbox = charProc.getGlyphBBox();
            if (bbox == null)
                bbox = charProc.getBBox();
            Integer code = f1NameToCode.get(key.getName());

            if (code != null)
            {
                PDDocument charDocument = new PDDocument();
                PDPage charPage = new PDPage(bbox);
                charDocument.addPage(charPage);
                charPage.setResources(pageResources);
                PDPageContentStream charContentStream = new PDPageContentStream(charDocument, charPage);
                charContentStream.beginText();
                charContentStream.setFont(fontF1, bbox.getHeight());
                charContentStream.getOutput().write(String.format("<%2X> Tj\n", code).getBytes());
                charContentStream.endText();
                charContentStream.close();

                File result = new File(RESULT_FOLDER, String.format("4700198773-%s-%s.png", key.getName(), code));
                PDFRenderer renderer = new PDFRenderer(charDocument);
                BufferedImage image = renderer.renderImageWithDPI(0, 96);
                ImageIO.write(image, "PNG", result);
                charDocument.save(new File(RESULT_FOLDER, String.format("4700198773-%s-%s.pdf", key.getName(), code)));
                charDocument.close();
            }
        }
    }
}
 
Example 3
Project: IDBuilderFX   File: ExtractPhoto.java   Source Code and License 7 votes vote down vote up
public static void findPhoto(String path,int empId) throws IOException, SQLException, Error{
		// Loading an existing document
		int imageFound=0;
		File file = new File(path);
		PDDocument document=PDDocument.load(file);
		PDPageTree list=document.getPages();
		for(PDPage page:list){						//check in all pages of pdf
			PDResources pdResources=page.getResources();		//get all resources
			for(COSName cosName:pdResources.getXObjectNames())		//loop for all resources
			{
				PDXObject pdxObject=pdResources.getXObject(cosName);
				 if (pdxObject instanceof PDImageXObject) {			//check that the resource is image
		                BufferedImage br=((PDImageXObject) pdxObject).getImage();
		                RgbImage im = RgbImageJ2se.toRgbImage(br);
		                // step #3 - convert image to greyscale 8-bits
		                RgbAvgGray toGray = new RgbAvgGray();
		                toGray.push(im);
		                // step #4 - initialize face detector with correct Haar profile
		                InputStream is  = ExtractPhoto.class.getResourceAsStream("/haar/HCSB.txt");
		                Gray8DetectHaarMultiScale detectHaar = new Gray8DetectHaarMultiScale(is, 1,40);
		                // step #5 - apply face detector to grayscale image
		                List<Rect> result= detectHaar.pushAndReturn(toGray.getFront());
		                if(result.size()!=0)
		                {
		                database.StorePhoto.storePhoto(empId,br);
		                imageFound=1;
		                break;
		                }
				 }
			}
			if(imageFound==1)
				break;
}
		System.out.println(imageFound);
		if(imageFound!=1){
			BufferedImage in = ImageIO.read(ExtractPhoto.class.getResource("/images/nopic.jpg"));
            database.StorePhoto.storePhoto(empId,in);
		}
	document.close();	
	}
 
Example 4
Project: oma-riista-web   File: HunterPaymentPdfFeature.java   Source Code and License 7 votes vote down vote up
public byte[] build() throws IOException {
    this.acroForm.setNeedAppearances(false);

    // Fix annotations
    for (PDPage page : this.pdfDocument.getPages()) {
        for (PDAnnotation annot : page.getAnnotations()) {
            annot.setPage(page);
        }
    }

    // Define font resources names used in PDF template
    final PDResources dr = new PDResources();
    dr.put(COSName.getPDFName("Helv"), PDType1Font.HELVETICA);
    dr.put(COSName.getPDFName("HeBo"), PDType1Font.HELVETICA_BOLD);
    this.acroForm.setDefaultResources(dr);

    // Convert form fields to text
    this.acroForm.flatten();

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    pdfDocument.save(bos);
    pdfDocument.close();
    return bos.toByteArray();
}
 
Example 5
Project: testarea-pdfbox2   File: ExtractText.java   Source Code and License 7 votes vote down vote up
/**
 * <a href="https://stackoverflow.com/questions/45895768/pdfbox-2-0-7-extracttext-not-working-but-1-8-13-does-and-pdfreader-as-well">
 * PDFBox 2.0.7 ExtractText not working but 1.8.13 does and PDFReader as well
 * </a>
 * <br/>
 * <a href="https://wetransfer.com/downloads/214674449c23713ee481c5a8f529418320170827201941/b2bea6">
 * test-2.pdf
 * </a>
 * <p>
 * Due to the broken <b>ToUnicode</b> maps the output of immediate text
 * extraction from this document is unsatisfying, cf. {@link #testTest2()}.
 * It can be improved by removing these <b>ToUnicode</b> maps as this test
 * shows.
 * </p>
 */
@Test
public void testNoToUnicodeTest2() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("test-2.pdf")    )
    {
        PDDocument document = PDDocument.load(resource);

        for (int pageNr = 0; pageNr < document.getNumberOfPages(); pageNr++)
        {
            PDPage page = document.getPage(pageNr);
            PDResources resources = page.getResources();
            removeToUnicodeMaps(resources);
        }

        PDFTextStripper stripper = new PDFTextStripper();
        String text = stripper.getText(document);

        System.out.printf("\n*\n* test-2.pdf without ToUnicode\n*\n%s\n", text);
        Files.write(new File(RESULT_FOLDER, "test-2_NoToUnicode.txt").toPath(), Collections.singleton(text));
    }
}
 
Example 6
Project: pdf-box-examples   File: PdfImagesHelper.java   Source Code and License 7 votes vote down vote up
private List<RenderedImage> getImagesFromResources(PDResources resources) throws IOException {

        List<RenderedImage> images = new ArrayList<>();
        for (COSName xObjectName : resources.getXObjectNames()) {
            PDXObject xObject = resources.getXObject(xObjectName);
            if (xObject instanceof PDImageXObject) {
                images.add(((PDImageXObject) xObject).getImage());
            } else if (xObject instanceof PDFormXObject) {
                images.addAll(getImagesFromResources(((PDFormXObject) xObject).getResources()));
            }
        }
        return images;
    }
 
Example 7
Project: testarea-pdfbox1   File: CreateCheckbox.java   Source Code and License 7 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/43604973/creating-a-checkbox-and-printing-it-to-pdf-file-is-not-working-using-pdfbox-1-8">
 * Creating a checkbox and printing it to pdf file is not working using pdfbox 1.8.9 api
 * </a>
 * <p>
 * The OP's method for checkbox creation.
 * </p>
 * @see #testCheckboxLikeSureshGoud()
 */
public static void writeInputFieldToPDFPage( PDPage pdPage, PDDocument document, Float x, Float y, Boolean ticked) throws IOException {
    PDFont font = PDType1Font.HELVETICA;
    PDResources res = new PDResources();
    String fontName = res.addFont(font);
    String da = ticked?"/" + fontName + " 10 Tf 0 0.4 0 rg":"";

    COSDictionary acroFormDict = new COSDictionary();
    acroFormDict.setBoolean(COSName.getPDFName("NeedAppearances"), true);
    acroFormDict.setItem(COSName.FIELDS, new COSArray());
    acroFormDict.setItem(COSName.DA, new COSString(da));

    PDAcroForm acroForm =  new PDAcroForm(document, acroFormDict);
    acroForm.setDefaultResources(res);
    document.getDocumentCatalog().setAcroForm(acroForm);

    PDGamma colourBlack = new PDGamma();
    PDAppearanceCharacteristicsDictionary fieldAppearance =
        new PDAppearanceCharacteristicsDictionary(new COSDictionary());
    fieldAppearance.setBorderColour(colourBlack);
    if(ticked) {
        COSArray arr = new COSArray();
        arr.add(new COSFloat(0.89f));
        arr.add(new COSFloat(0.937f));
        arr.add(new COSFloat(1f));
        fieldAppearance.setBackground(new PDGamma(arr));
    }

    COSDictionary cosDict = new COSDictionary();
    COSArray rect = new COSArray();

    rect.add(new COSFloat(x));
    rect.add(new COSFloat(new Float(y-5)));
    rect.add(new COSFloat(new Float(x+10)));
    rect.add(new COSFloat(new Float(y+5)));

    cosDict.setItem(COSName.RECT, rect);
    cosDict.setItem(COSName.FT, COSName.getPDFName("Btn")); // Field Type
    cosDict.setItem(COSName.TYPE, COSName.ANNOT);
    cosDict.setItem(COSName.SUBTYPE, COSName.getPDFName("Widget"));
    if(ticked) {
        cosDict.setItem(COSName.TU, new COSString("Checkbox with PDFBox"));
    }
    cosDict.setItem(COSName.T, new COSString("Chk"));
    //Tick mark color and size of the mark
    cosDict.setItem(COSName.DA, new COSString(ticked?"/F0 10 Tf 0 0.4 0 rg":"/FF 1 Tf 0 0 g"));
    cosDict.setInt(COSName.F, 4);

    PDCheckbox checkbox = new PDCheckbox(acroForm, cosDict);
    checkbox.setFieldFlags(PDCheckbox.FLAG_READ_ONLY);
    checkbox.setValue("Yes");

    checkbox.getWidget().setAppearanceCharacteristics(fieldAppearance);

    pdPage.getAnnotations().add(checkbox.getWidget());
    acroForm.getFields().add(checkbox);
}
 
Example 8
Project: testarea-pdfbox1   File: RolloverAnnotation.java   Source Code and License 7 votes vote down vote up
PDAppearanceStream createAppearanceStream(PDDocument document, float width, PDFont font, String backColorSettingOperation) throws IOException
{
    PDResources pdResources = new PDResources();
    String fontName = pdResources.addFont(font);
    PDStream pdStream = new PDStream(document);
    OutputStream os = pdStream.createOutputStream();
    String streamToBe = backColorSettingOperation + " 0 -5 " + width + " 25 re f /" + fontName + " 18 Tf 0 g BT (PDFBox) Tj ET";
    os.write(streamToBe.getBytes());
    os.close();
    
    PDXObjectForm xobject = new PDXObjectForm(pdStream);
    xobject.setResources(pdResources);
    xobject.setBBox(new PDRectangle(new BoundingBox(0, -5, width, 20)));
    xobject.setFormType(1);
    PDAppearanceStream normal = new PDAppearanceStream(xobject.getCOSStream());
    return normal;
}
 
Example 9
Project: pdfbox-graphics2d   File: PdfBoxGraphics2D.java   Source Code and License 6 votes vote down vote up
/**
 * @param document
 *            The document the graphics should be used to create a XForm in.
 * @param bbox
 *            Bounding Box of the graphics
 * @throws IOException
 *             when something goes wrong with writing into the content
 *             stream of the {@link PDDocument}.
 */
public PdfBoxGraphics2D(PDDocument document, PDRectangle bbox) throws IOException {
	this.document = document;
	this.bbox = bbox;

	PDAppearanceStream appearance = new PDAppearanceStream(document);
	xFormObject = appearance;
	xFormObject.setResources(new PDResources());
	xFormObject.setBBox(bbox);
	contentStream = new PDPageContentStream(document, appearance, xFormObject.getStream().createOutputStream(COSName.FLATE_DECODE));
	contentStreamSaveState();

	baseTransform = new AffineTransform();
	baseTransform.translate(0, bbox.getHeight());
	baseTransform.scale(1, -1);

	calcImage = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR);
	calcGfx = calcImage.createGraphics();
	font = calcGfx.getFont();
	cloneInfo = null;
}
 
Example 10
Project: memoria-politica   File: FedDepPhotosUtility.java   Source Code and License 6 votes vote down vote up
private static void buildImgKeyToImageObjMapping(PDPage page) throws IOException {
    PDResources resources = page.getResources();
    Map images = resources.getImages();

    if(images != null) {
        Iterator imageIter = images.keySet().iterator();

        while(imageIter.hasNext()) {
            String key = (String)imageIter.next();
            PDXObjectImage image = (PDXObjectImage)images.get(key);
            mapImgKeyToImageObj.put(key, image);
        }
    }
}
 
Example 11
Project: FontVerter   File: PdfFontExtractor.java   Source Code and License 6 votes vote down vote up
private void extractFontResources(PDResources resources) throws IOException {
    for (COSName key : resources.getFontNames()) {
        PDFont font = resources.getFont(key);
        extractStrategy.extract(font);
    }

    for (COSName name : resources.getXObjectNames()) {
        PDXObject xobject = resources.getXObject(name);
        if (xobject instanceof PDFormXObject) {
            PDFormXObject xObjectForm = (PDFormXObject) xobject;
            PDResources formResources = xObjectForm.getResources();

            if (formResources != null)
                extractFontResources(formResources);
        }
    }
}
 
Example 12
Project: testarea-pdfbox2   File: TestEmptySignatureField.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/37601092/pdfbox-identify-specific-pages-and-functionalities-recommendations">
 * PDFBox identify specific pages and functionalities recommendations
 * </a>
 * 
 * <p>
 * This test shows how to add an empty signature field with a custom appearance
 * to an existing PDF.
 * </p>
 */
@Test
public void testAddEmptySignatureField() throws IOException
{
    try (   InputStream sourceStream = getClass().getResourceAsStream("test.pdf");
            OutputStream output = new FileOutputStream(new File(RESULT_FOLDER, "test-with-empty-sig-field.pdf")))
    {
        PDFont font = PDType1Font.HELVETICA;
        PDResources resources = new PDResources();
        resources.put(COSName.getPDFName("Helv"), font);

        PDDocument document = PDDocument.load(sourceStream);
        PDAcroForm acroForm = new PDAcroForm(document);
        acroForm.setDefaultResources(resources);
        document.getDocumentCatalog().setAcroForm(acroForm);

        PDRectangle rect = new PDRectangle(50, 750, 200, 50);

        PDAppearanceDictionary appearanceDictionary = new PDAppearanceDictionary();
        PDAppearanceStream appearanceStream = new PDAppearanceStream(document);
        appearanceStream.setBBox(rect.createRetranslatedRectangle());
        appearanceStream.setResources(resources);
        appearanceDictionary.setNormalAppearance(appearanceStream);
        PDPageContentStream contentStream = new PDPageContentStream(document, appearanceStream);
        contentStream.setStrokingColor(Color.BLACK);
        contentStream.setNonStrokingColor(Color.LIGHT_GRAY);
        contentStream.setLineWidth(2);
        contentStream.addRect(0, 0, rect.getWidth(), rect.getHeight());
        contentStream.fill();
        contentStream.moveTo(1 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
        contentStream.lineTo(2 * rect.getHeight() / 4, 3 * rect.getHeight() / 4);
        contentStream.moveTo(1 * rect.getHeight() / 4, 3 * rect.getHeight() / 4);
        contentStream.lineTo(2 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
        contentStream.moveTo(3 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
        contentStream.lineTo(rect.getWidth() - rect.getHeight() / 4, 1 * rect.getHeight() / 4);
        contentStream.stroke();
        contentStream.setNonStrokingColor(Color.DARK_GRAY);
        contentStream.beginText();
        contentStream.setFont(font, rect.getHeight() / 5);
        contentStream.newLineAtOffset(3 * rect.getHeight() / 4, -font.getBoundingBox().getLowerLeftY() * rect.getHeight() / 5000);
        contentStream.showText("Customer");
        contentStream.endText();
        contentStream.close();

        PDSignatureField signatureField = new PDSignatureField(acroForm);
        signatureField.setPartialName("SignatureField");
        PDPage page = document.getPage(0);

        PDAnnotationWidget widget = signatureField.getWidgets().get(0);
        widget.setAppearance(appearanceDictionary);
        widget.setRectangle(rect);
        widget.setPage(page);

        page.getAnnotations().add(widget);
        acroForm.getFields().add(signatureField);

        document.save(output);
        document.close();
    }
}
 
Example 13
Project: testarea-pdfbox2   File: ExtractImages.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/40531871/how-can-i-check-if-pdf-page-is-imagescanned-by-pdfbox-xpdf">
 * How can I check if PDF page is image(scanned) by PDFBOX, XPDF
 * </a>
 * <br/>
 * <a href="https://drive.google.com/file/d/0B9izTHWJQ7xlT2ZoQkJfbGRYcFE">
 * 10948.pdf
 * </a>
 * <p>
 * The only special thing about the two images returned for the sample PDF is that
 * one image is merely a mask used for the other image, and the other image is the
 * actual image used on the PDF page. If one only wants the images immediately used
 * in the page content, one also has to scan the page content.
 * </p>
 */
@Test
public void testExtractPageImageResources10948() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("10948.pdf"))
    {
        PDDocument document = PDDocument.load(resource);
        int page = 1;
        for (PDPage pdPage : document.getPages())
        {
            PDResources resources = pdPage.getResources();
            if (resource != null)
            {
                int index = 0;
                for (COSName cosName : resources.getXObjectNames())
                {
                    PDXObject xobject = resources.getXObject(cosName);
                    if (xobject instanceof PDImageXObject)
                    {
                        PDImageXObject image = (PDImageXObject)xobject;
                        File file = new File(RESULT_FOLDER, String.format("10948-%s-%s.%s", page, index, image.getSuffix()));
                        ImageIO.write(image.getImage(), image.getSuffix(), file);
                        index++;
                    }
                }
            }
            page++;
        }
    }
}
 
Example 14
Project: testarea-pdfbox2   File: ExtractImages.java   Source Code and License 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/40531871/how-can-i-check-if-pdf-page-is-imagescanned-by-pdfbox-xpdf">
 * How can I check if PDF page is image(scanned) by PDFBOX, XPDF
 * </a>
 * <br/>
 * <a href="https://drive.google.com/open?id=0B9izTHWJQ7xlYi1XN1BxMmZEUGc">
 * 10948.pdf
 * </a>, renamed "10948-new.pdf" here to prevent a collision
 * <p>
 * Here the code extracts no image at all because the images are not immediate page
 * resources but wrapped in form xobjects.
 * </p>
 */
@Test
public void testExtractPageImageResources10948New() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("10948-new.pdf"))
    {
        PDDocument document = PDDocument.load(resource);
        int page = 1;
        for (PDPage pdPage : document.getPages())
        {
            PDResources resources = pdPage.getResources();
            if (resource != null)
            {
                int index = 0;
                for (COSName cosName : resources.getXObjectNames())
                {
                    PDXObject xobject = resources.getXObject(cosName);
                    if (xobject instanceof PDImageXObject)
                    {
                        PDImageXObject image = (PDImageXObject)xobject;
                        File file = new File(RESULT_FOLDER, String.format("10948-new-%s-%s.%s", page, index, image.getSuffix()));
                        ImageIO.write(image.getImage(), image.getSuffix(), file);
                        index++;
                    }
                }
            }
            page++;
        }
    }
}
 
Example 15
Project: pdf-box-examples   File: PdfImagesHelper.java   Source Code and License 6 votes vote down vote up
private void drawXObject(PDImageXObject xobject, PDResources resources, OutputStream os,
                         float x, float y, float width, float height) throws IOException {
    // This is similar to PDPageContentStream.drawXObject()
    COSName xObjectId = resources.add(xobject);

    appendRawCommands(os, SAVE_GRAPHICS_STATE);
    appendRawCommands(os, formatDecimal.format(width));
    appendRawCommands(os, SPACE);
    appendRawCommands(os, formatDecimal.format(0));
    appendRawCommands(os, SPACE);
    appendRawCommands(os, formatDecimal.format(0));
    appendRawCommands(os, SPACE);
    appendRawCommands(os, formatDecimal.format(height));
    appendRawCommands(os, SPACE);
    appendRawCommands(os, formatDecimal.format(x));
    appendRawCommands(os, SPACE);
    appendRawCommands(os, formatDecimal.format(y));
    appendRawCommands(os, SPACE);
    appendRawCommands(os, CONCATENATE_MATRIX);
    appendRawCommands(os, SPACE);
    appendRawCommands(os, "/");
    appendRawCommands(os, xObjectId.getName());
    appendRawCommands(os, SPACE);
    appendRawCommands(os, XOBJECT_DO);
    appendRawCommands(os, SPACE);
    appendRawCommands(os, RESTORE_GRAPHICS_STATE);
}
 
Example 16
Project: icecite   File: PdfStreamEngine.java   Source Code and License 6 votes vote down vote up
/**
 * Pushes the given stream's resources, returning the previous resources.
 * 
 * @param stream
 *          the stream.
 * @return the resources.
 */
protected PDResources pushResources(PDContentStream stream) {
  // Lookup resources: first look for stream resources, then fallback to the
  // current page
  PDResources parentResources = resources;
  PDResources streamResources = stream.getResources();
  if (streamResources != null) {
    this.resources = streamResources;
  } else {
  // else if (resources != null) {
    // inherit directly from parent stream, this is not in the PDF spec, but
    // the file from PDFBOX-1359 does this and works in Acrobat
  // } 
    this.resources = currentPage.getResources();
  }

  // resources are required in PDF
  if (this.resources == null) {
    this.resources = new PDResources();
  }
  return parentResources;
}
 
Example 17
Project: testarea-pdfbox1   File: ExtractPatternImages.java   Source Code and License 6 votes vote down vote up
public void extractPatternImages(PDPatternResources pattern, String patternFormat) throws IOException
{
    COSDictionary resourcesDict = (COSDictionary) pattern.getCOSDictionary().getDictionaryObject(COSName.RESOURCES);
    if (resourcesDict == null)
        return;
    PDResources resources = new PDResources(resourcesDict);
    Map<String, PDXObject> xObjects = resources.getXObjects();
    if (xObjects == null)
        return;

    for (Map.Entry<String, PDXObject> entry : xObjects.entrySet())
    {
        PDXObject xObject = entry.getValue();
        String xObjectFormat = String.format(patternFormat, "-" + entry.getKey() + "%s", "%s");
        if (xObject instanceof PDXObjectForm)
            extractPatternImages((PDXObjectForm)xObject, xObjectFormat);
        else if (xObject instanceof PDXObjectImage)
            extractPatternImages((PDXObjectImage)xObject, xObjectFormat);
    }
}
 
Example 18
Project: testarea-pdfbox1   File: ExtractAnnotationImageTest.java   Source Code and License 6 votes vote down vote up
public void extractAnnotationImages(PDAppearanceStream appearance, String appearanceFormat) throws IOException
{
    PDResources resources = appearance.getResources();
    if (resources == null)
        return;
    Map<String, PDXObject> xObjects = resources.getXObjects();
    if (xObjects == null)
        return;

    for (Map.Entry<String, PDXObject> entry : xObjects.entrySet())
    {
        PDXObject xObject = entry.getValue();
        String xObjectFormat = String.format(appearanceFormat, "-" + entry.getKey() + "%s", "%s");
        if (xObject instanceof PDXObjectForm)
            extractAnnotationImages((PDXObjectForm)xObject, xObjectFormat);
        else if (xObject instanceof PDXObjectImage)
            extractAnnotationImages((PDXObjectImage)xObject, xObjectFormat);
    }
}
 
Example 19
Project: testarea-pdfbox1   File: ExtractAnnotationImageTest.java   Source Code and License 6 votes vote down vote up
public void extractAnnotationImages(PDXObjectForm form, String imageFormat) throws IOException
{
    PDResources resources = form.getResources();
    if (resources == null)
        return;
    Map<String, PDXObject> xObjects = resources.getXObjects();
    if (xObjects == null)
        return;

    for (Map.Entry<String, PDXObject> entry : xObjects.entrySet())
    {
        PDXObject xObject = entry.getValue();
        String xObjectFormat = String.format(imageFormat, "-" + entry.getKey() + "%s", "%s");
        if (xObject instanceof PDXObjectForm)
            extractAnnotationImages((PDXObjectForm)xObject, xObjectFormat);
        else if (xObject instanceof PDXObjectImage)
            extractAnnotationImages((PDXObjectImage)xObject, xObjectFormat);
    }
}
 
Example 20
Project: OCRaptor   File: PDF2XHTML.java   Source Code and License 6 votes vote down vote up
/**
 *
 *
 * @param pdf
 *
 * @throws SAXException
 */
private void extractImageText(PDDocument pdf) {
  List<?> pages = pdf.getDocumentCatalog().getAllPages();
  Iterator<?> pageIterator = pages.iterator();
  pageCount = pages.size();
  imageCount = 0;
  int currentPage = 0;
  TikaImageHelper helper = new TikaImageHelper(this.metadata);
  try {
    while (pageIterator.hasNext()) {
      PDPage page = (PDPage) pageIterator.next();
      PDResources resources = page.getResources();
      processResources(resources, helper);
      helper.addTextToHandler(handler, ++currentPage, pageCount);
    }
  } catch (Exception e) {
    e.printStackTrace();
  } finally {
    if (helper != null) {
      helper.close();
    }
  }
}
 
Example 21
Project: PDFGal   File: WatermarkUtilsImpl.java   Source Code and License 6 votes vote down vote up
@Override
public void setUpGraphicState(final PDPage page, final Float alpha) {

	if (page != null && alpha != null) {

		// Define a new extended graphic state
		final PDExtendedGraphicsState extendedGraphicsState = new PDExtendedGraphicsState();
		// Set the transparency/opacity
		extendedGraphicsState.setNonStrokingAlphaConstant(alpha);
		// Get the page resources.
		final PDResources resources = page.findResources();

		// Get the defined graphic states.
		final Map<String, PDExtendedGraphicsState> graphicsStateDictionary = resources
				.getGraphicsStates();

		graphicsStateDictionary.put("TransparentState", extendedGraphicsState);
		resources.setGraphicsStates(graphicsStateDictionary);
	}
}
 
Example 22
Project: Pdf2Dom   File: PDFBoxTree.java   Source Code and License 6 votes vote down vote up
private void processFontResources(PDResources resources, FontTable table) throws IOException
{
    String fontNotSupportedMessage = "Font: {} skipped because type '{}' is not supported.";

    for (COSName key : resources.getFontNames())
    {
        PDFont font = resources.getFont(key);
        if (font instanceof PDTrueTypeFont)
        {
            table.addEntry( font);
            log.debug("Font: " + font.getName() + " TTF");
        }
        else if (font instanceof PDType0Font)
        {
            PDCIDFont descendantFont = ((PDType0Font) font).getDescendantFont();
            if (descendantFont instanceof PDCIDFontType2)
                table.addEntry(font);
            else
                log.warn(fontNotSupportedMessage, font.getName(), font.getClass().getSimpleName());
        }
        else if (font instanceof PDType1CFont)
            table.addEntry(font);
        else
            log.warn(fontNotSupportedMessage, font.getName(), font.getClass().getSimpleName());
    }

    for (COSName name : resources.getXObjectNames())
    {
        PDXObject xobject = resources.getXObject(name);
        if (xobject instanceof PDFormXObject)
        {
            PDFormXObject xObjectForm = (PDFormXObject) xobject;
            PDResources formResources = xObjectForm.getResources();
            if (formResources != null)
                processFontResources(formResources, table);
        }
    }

}
 
Example 23
Project: pdfbox-graphics2d   File: PdfBoxGraphics2D.java   Source Code and License 5 votes vote down vote up
private PDShading applyPaint(Paint paintToApply) throws IOException {
	AffineTransform tf = new AffineTransform(baseTransform);
	tf.concatenate(transform);
	return paintApplier.applyPaint(paintToApply, contentStream, tf, new IPdfBoxGraphics2DPaintApplier.IPaintEnv() {
		@Override
		public IPdfBoxGraphics2DColorMapper getColorMapper() {
			return colorMapper;
		}

		@Override
		public IPdfBoxGraphics2DImageEncoder getImageEncoder() {
			return imageEncoder;
		}

		@Override
		public PDDocument getDocument() {
			return document;
		}

		@Override
		public PDResources getResources() {
			return xFormObject.getResources();
		}

		@Override
		public Composite getComposite() {
			return PdfBoxGraphics2D.this.getComposite();
		}
	});
}
 
Example 24
Project: FontVerter   File: PdfFontExtractor.java   Source Code and License 5 votes vote down vote up
protected void tryExtractPageFonts() {
    PDResources resources = pdpage.getResources();
    if (resources == null)
        return;

    try {
        extractFontResources(resources);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 25
Project: printability-validator   File: PdfFontValidator.java   Source Code and License 5 votes vote down vote up
public Collection<PDFont> getPageFonts(PDPage page) throws IOException {
    PDResources resources = page.getResources();
    if (resources != null) {
        Map<String, PDFont> fontMap = resources.getFonts();
        return fontMap.values();
    }
    return emptySet();
}
 
Example 26
Project: icecite   File: PdfStreamEngine.java   Source Code and License 5 votes vote down vote up
/**
 * Processes a content stream.
 * 
 * @param stream
 *          the content stream
 * @throws IOException
 *           if there is an exception while processing the stream
 */
public void processStream(PDContentStream stream) throws IOException {
  if (stream != null) {
    PDResources parent = pushResources(stream);
    Stack<PDGraphicsState> savedStack = saveGraphicsStack();
    Matrix parentMatrix = initialMatrix;

    // Transform the CTM using the stream's matrix.
    getCurrentTransformationMatrix().concatenate(stream.getMatrix());

    // The stream's initial matrix includes the parent CTM, e.g. this allows 
    // a scaled form.
    this.initialMatrix = getCurrentTransformationMatrix().clone();

    // TODO: Do we need this snippet?
    // clip to bounding box
    // PDRectangle bbox = stream.getBBox();
    // clipToRect(bbox);

    processStreamOperators(stream);
    
    // Restore the initialMatrix, the graphics stack and the resources.
    this.initialMatrix = parentMatrix;
    restoreGraphicsStack(savedStack);
    popResources(parent);
  }
}
 
Example 27
Project: icecite   File: PdfStreamEngine.java   Source Code and License 5 votes vote down vote up
/**
 * Processes a type 3 character stream.
 * 
 * @param charProc
 *          Type 3 character procedure
 * @param trm
 *          the text Rendering Matrix
 * @throws IOException
 *           if processing the type stream fails.
 */
public void processType3Stream(PDType3CharProc charProc, Matrix trm) 
    throws IOException {
  PDResources parent = pushResources(charProc);
  Stack<PDGraphicsState> savedStack = saveGraphicsStack();

  // Replace the CTM with the TRM
  setCurrentTransformationMatrix(trm);
  
  // Rransform the CTM using the stream's matrix (this is the FontMatrix)
  getCurrentTransformationMatrix().concatenate(charProc.getMatrix());
  
  // Save text matrices (Type 3 stream may contain BT/ET, see PDFBOX-2137)
  Matrix oldTextMatrix = getTextMatrix();
  setTextMatrix(new Matrix());
  Matrix oldTextLineMatrix = getTextLineMatrix();
  setTextLineMatrix(new Matrix());

  setIsType3Stream(true);
  processStreamOperators(charProc);
  setIsType3Stream(false);    
  
  // Restore text matrices
  setTextMatrix(oldTextMatrix);
  setTextLineMatrix(oldTextLineMatrix);

  restoreGraphicsStack(savedStack);
  popResources(parent);
}
 
Example 28
Project: testarea-pdfbox1   File: PrintPaths.java   Source Code and License 5 votes vote down vote up
@Override
public void processStream(PDPage aPage, PDResources resources, COSStream cosStream) throws IOException
{
    PDRectangle cropBox = aPage.findCropBox();
    this.pageSize = cropBox.createDimension();
    super.processStream(aPage, resources, cosStream);
}
 
Example 29
Project: testarea-pdfbox1   File: ExtractPatternImages.java   Source Code and License 5 votes vote down vote up
public void extractPatternImages(PDPage page, String pageFormat) throws IOException
{
    PDResources resources = page.getResources();
    if (resources == null)
        return;
    Map<String, PDPatternResources> patterns = resources.getPatterns();
    
    for (Map.Entry<String, PDPatternResources> patternEntry : patterns.entrySet())
    {
        String patternFormat = String.format(pageFormat, "-" + patternEntry.getKey() + "%s", "%s");
        extractPatternImages(patternEntry.getValue(), patternFormat);
    }
}
 
Example 30
Project: testarea-pdfbox1   File: ExtractPatternImages.java   Source Code and License 5 votes vote down vote up
public void extractPatternImages(PDXObjectForm form, String imageFormat) throws IOException
{
    PDResources resources = form.getResources();
    if (resources == null)
        return;
    Map<String, PDXObject> xObjects = resources.getXObjects();
    if (xObjects == null)
        return;

    for (Map.Entry<String, PDXObject> entry : xObjects.entrySet())
    {
        PDXObject xObject = entry.getValue();
        String xObjectFormat = String.format(imageFormat, "-" + entry.getKey() + "%s", "%s");
        if (xObject instanceof PDXObjectForm)
            extractPatternImages((PDXObjectForm)xObject, xObjectFormat);
        else if (xObject instanceof PDXObjectImage)
            extractPatternImages((PDXObjectImage)xObject, xObjectFormat);
    }

    Map<String, PDPatternResources> patterns = resources.getPatterns();
    
    for (Map.Entry<String, PDPatternResources> patternEntry : patterns.entrySet())
    {
        String patternFormat = String.format(imageFormat, "-" + patternEntry.getKey() + "%s", "%s");
        extractPatternImages(patternEntry.getValue(), patternFormat);
    }
}
 
Example 31
Project: omr   File: JazzPDFReader.java   Source Code and License 5 votes vote down vote up
@Test
public void testPDFBox() throws IOException {

	PDDocument document = null;

	File file = new File(JazzPDFReader.PDF_TESTE);

	document = PDDocument.load(file);

	List pages = document.getDocumentCatalog().getAllPages();

	for (Object object : pages) {

		PDPage page = (PDPage) object;
		PDResources resources = page.getResources();
		Map images = resources.getImages();
		if (images != null) {
			Set keySet = images.keySet();
			Iterator imageIter = keySet.iterator();
			while (imageIter.hasNext()) {
				String key = (String) imageIter.next();
				PDXObjectImage image = (PDXObjectImage) images.get(key);
				BufferedImage bufferedImage = image.getRGBImage();

				ImageIO.write(bufferedImage, "jpg", new File("/home/darcio/Desktop/ExamePDFTeste/pdfbox/imgFromPDFBOX" + System.currentTimeMillis() + ".jpg"));
			}
		}
	}
}
 
Example 32
Project: omr   File: JazzPDFReader.java   Source Code and License 5 votes vote down vote up
@Test
public void testPDFBox() throws IOException {

	PDDocument document = null;

	File file = new File(JazzPDFReader.PDF_TESTE);

	document = PDDocument.load(file);

	List pages = document.getDocumentCatalog().getAllPages();

	for (Object object : pages) {

		PDPage page = (PDPage) object;
		PDResources resources = page.getResources();
		Map images = resources.getImages();
		if (images != null) {
			Set keySet = images.keySet();
			Iterator imageIter = keySet.iterator();
			while (imageIter.hasNext()) {
				String key = (String) imageIter.next();
				PDXObjectImage image = (PDXObjectImage) images.get(key);
				BufferedImage bufferedImage = image.getRGBImage();

				ImageIO.write(bufferedImage, "jpg", new File("/home/darcio/Desktop/ExamePDFTeste/pdfbox/imgFromPDFBOX" + System.currentTimeMillis() + ".jpg"));
			}
		}
	}
}
 
Example 33
Project: omr   File: JazzPDFReader.java   Source Code and License 5 votes vote down vote up
@Test
public void testPDFBox() throws IOException {

	PDDocument document = null;

	File file = new File(JazzPDFReader.PDF_TESTE);

	document = PDDocument.load(file);

	List pages = document.getDocumentCatalog().getAllPages();

	for (Object object : pages) {

		PDPage page = (PDPage) object;
		PDResources resources = page.getResources();
		Map images = resources.getImages();
		if (images != null) {
			Set keySet = images.keySet();
			Iterator imageIter = keySet.iterator();
			while (imageIter.hasNext()) {
				String key = (String) imageIter.next();
				PDXObjectImage image = (PDXObjectImage) images.get(key);
				BufferedImage bufferedImage = image.getRGBImage();

				ImageIO.write(bufferedImage, "jpg", new File("/home/darcio/Desktop/ExamePDFTeste/pdfbox/imgFromPDFBOX" + System.currentTimeMillis() + ".jpg"));
			}
		}
	}
}
 
Example 34
Project: omr   File: JazzPDFReader.java   Source Code and License 5 votes vote down vote up
@Test
public void testPDFBox() throws IOException {

	PDDocument document = null;

	File file = new File(JazzPDFReader.PDF_TESTE);

	document = PDDocument.load(file);

	List pages = document.getDocumentCatalog().getAllPages();

	for (Object object : pages) {

		PDPage page = (PDPage) object;
		PDResources resources = page.getResources();
		Map images = resources.getImages();
		if (images != null) {
			Set keySet = images.keySet();
			Iterator imageIter = keySet.iterator();
			while (imageIter.hasNext()) {
				String key = (String) imageIter.next();
				PDXObjectImage image = (PDXObjectImage) images.get(key);
				BufferedImage bufferedImage = image.getRGBImage();

				ImageIO.write(bufferedImage, "jpg", new File("/home/darcio/Desktop/ExamePDFTeste/pdfbox/imgFromPDFBOX" + System.currentTimeMillis() + ".jpg"));
			}
		}
	}
}
 
Example 35
Project: omr   File: JazzPDFReader.java   Source Code and License 5 votes vote down vote up
@Test
public void testPDFBox() throws IOException {

	PDDocument document = null;

	File file = new File(JazzPDFReader.PDF_TESTE);

	document = PDDocument.load(file);

	List pages = document.getDocumentCatalog().getAllPages();

	for (Object object : pages) {

		PDPage page = (PDPage) object;
		PDResources resources = page.getResources();
		Map images = resources.getImages();
		if (images != null) {
			Set keySet = images.keySet();
			Iterator imageIter = keySet.iterator();
			while (imageIter.hasNext()) {
				String key = (String) imageIter.next();
				PDXObjectImage image = (PDXObjectImage) images.get(key);
				BufferedImage bufferedImage = image.getRGBImage();

				ImageIO.write(bufferedImage, "jpg", new File("/home/darcio/Desktop/ExamePDFTeste/pdfbox/imgFromPDFBOX" + System.currentTimeMillis() + ".jpg"));
			}
		}
	}
}
 
Example 36
Project: omr   File: JazzPDFReader.java   Source Code and License 5 votes vote down vote up
@Test
public void testPDFBox() throws IOException {

	PDDocument document = null;

	File file = new File(JazzPDFReader.PDF_TESTE);

	document = PDDocument.load(file);

	List pages = document.getDocumentCatalog().getAllPages();

	for (Object object : pages) {

		PDPage page = (PDPage) object;
		PDResources resources = page.getResources();
		Map images = resources.getImages();
		if (images != null) {
			Set keySet = images.keySet();
			Iterator imageIter = keySet.iterator();
			while (imageIter.hasNext()) {
				String key = (String) imageIter.next();
				PDXObjectImage image = (PDXObjectImage) images.get(key);
				BufferedImage bufferedImage = image.getRGBImage();

				ImageIO.write(bufferedImage, "jpg", new File("/home/darcio/Desktop/ExamePDFTeste/pdfbox/imgFromPDFBOX" + System.currentTimeMillis() + ".jpg"));
			}
		}
	}
}
 
Example 37
Project: OCRaptor   File: PDF2XHTML.java   Source Code and License 5 votes vote down vote up
/**
 *
 *
 * @param resources
 *
 * @throws IOException
 */
private void processResources(PDResources resources, TikaImageHelper helper)
throws IOException {
  if (resources == null)
    return;

  try {
    Map<String, PDXObject> xobjects = resources.getXObjects();
    if (xobjects != null) {
      Iterator<String> xobjectIter = xobjects.keySet().iterator();
      while (xobjectIter.hasNext()) {
        String key = xobjectIter.next();
        PDXObject xobject = xobjects.get(key);
        // write the images
        if (xobject instanceof PDXObjectImage) {
          PDXObjectImage image = (PDXObjectImage) xobject;
          if (ImageTools.imagePerPageRatioValid(imageCount++, pageCount)
              && ImageTools.imageSizeValid(image.getHeight(), image.getWidth())) {
            BufferedImage buffImage = image.getRGBImage();
            helper.addImage(buffImage);
          }
        }
        // maybe there are more images embedded in a form object
        else if (xobject instanceof PDXObjectForm) {
          if (ImageTools.imagePerPageRatioValid(imageCount, pageCount)) {
            PDXObjectForm xObjectForm = (PDXObjectForm) xobject;
            PDResources formResources = xObjectForm.getResources();
            processResources(formResources, helper);
          }
        }
      }
    }
  } catch (Exception e) {
    LOG.info("Shit happened", e);
  }

}
 
Example 38
Project: Pdf2Dom   File: PDFBoxTree.java   Source Code and License 5 votes vote down vote up
/**
 * Updates the font table by adding new fonts used at the current page.
 */
protected void updateFontTable()
{
    PDResources resources = pdpage.getResources();
    if (resources != null)
    {
        try
        {
            processFontResources(resources, fontTable);
        } catch (IOException e) {
            log.error("Error processing font resources: "
                    + "Exception: {} {}", e.getMessage(), e.getClass());
        }
    }
}
 
Example 39
Project: shrink-pdf   File: ShrinkPDF.java   Source Code and License 5 votes vote down vote up
private void scanResources(final PDResources rList, final PDDocument doc)
      throws FileNotFoundException, IOException {
    Map<String, PDXObject> xObs = rList.getXObjects();
    for(String k : xObs.keySet()) {
       final PDXObject xObj = xObs.get(k);
       if(xObj instanceof PDXObjectForm)
            scanResources(((PDXObjectForm) xObj).getResources(), doc);
       if(!(xObj instanceof PDXObjectImage))
            continue;
       PDXObjectImage img = (PDXObjectImage) xObj;
       System.out.println("Compressing image: " + k);
       final Iterator<ImageWriter> jpgWriters = 
               ImageIO.getImageWritersByFormatName("jpeg");
       final ImageWriter jpgWriter = jpgWriters.next();
       final ImageWriteParam iwp = jpgWriter.getDefaultWriteParam();
       iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
       iwp.setCompressionQuality(compQual);
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       jpgWriter.setOutput(ImageIO.createImageOutputStream(baos));
       jpgWriter.write(null,
               new IIOImage(img.getRGBImage(), null, null), iwp);
       ByteArrayInputStream bais = 
               new ByteArrayInputStream(baos.toByteArray());
       PDJpeg jpg = new PDJpeg(doc, bais);
       xObs.put(k, jpg);
    }
    rList.setXObjects(xObs);
}
 
Example 40
Project: testarea-pdfbox2   File: ExtractText.java   Source Code and License 4 votes vote down vote up
void removeToUnicodeMaps(PDResources pdResources) throws IOException
{
    COSDictionary resources = pdResources.getCOSObject();

    COSDictionary fonts = asDictionary(resources, COSName.FONT);
    if (fonts != null)
    {
        for (COSBase object : fonts.getValues())
        {
            while (object instanceof COSObject)
                object = ((COSObject)object).getObject();
            if (object instanceof COSDictionary)
            {
                COSDictionary font = (COSDictionary)object;
                font.removeItem(COSName.TO_UNICODE);
            }
        }
    }

    for (COSName name : pdResources.getXObjectNames())
    {
        PDXObject xobject = pdResources.getXObject(name);
        if (xobject instanceof PDFormXObject)
        {
            PDResources xobjectPdResources = ((PDFormXObject)xobject).getResources();
            removeToUnicodeMaps(xobjectPdResources);
        }
    }
}