pdfbox

How to delete an optional content group alongwith its content from pdf using pdfbox?

Deadly 提交于 2019-12-02 11:53:23
问题 I have implemented functionality to delete the layer from pdf, but the problem is that, the content that I had drawn on the layer, does not get delete.Here is the code that I am using to delete the layer: PDDocumentCatalog documentCatalog = doc.getDocumentCatalog(); PDOptionalContentProperties ocgProps = documentCatalog.getOCProperties(); PDOptionalContentGroup ocg = ocgProps.getGroup(markupLayerName); COSDictionary ocgsDict = (COSDictionary)ocgProps.getCOSObject(); COSArray ocgs = (COSArray

PdfBox - PDColorSpaceFactory.createColorSpace(document, iccColorSpace) throws nullpointerexception

别来无恙 提交于 2019-12-02 11:29:29
问题 I'm trying to create a PDF which has a single image on a single page. The tricky part is to use a custom (defined in a separate file) CMYK color space. I've tried to call PDColorSpaceFactory.createColorSpace(document, iccColorSpace) but keep getting nullpointerexception. I've managed to track the issue up to the constructor: public PDICCBased( PDDocument doc ) { array = new COSArray(); array.add( COSName.ICCBASED ); array.add( new PDStream( doc ) ); } The PDICCBased object has stream field

Apache PDFBox: Can I set font other than those present in PDType1Font

倾然丶 夕夏残阳落幕 提交于 2019-12-02 11:09:28
I can see only 4 fonts with variants in PDType1Font. Is there any way I can use other / custom fonts? PDFType1Font fonts public static final PDType1Font TIMES_ROMAN = new PDType1Font("Times-Roman"); public static final PDType1Font TIMES_BOLD = new PDType1Font("Times-Bold"); public static final PDType1Font TIMES_ITALIC = new PDType1Font("Times-Italic"); public static final PDType1Font TIMES_BOLD_ITALIC = new PDType1Font("Times-BoldItalic"); public static final PDType1Font HELVETICA = new PDType1Font("Helvetica"); public static final PDType1Font HELVETICA_BOLD = new PDType1Font("Helvetica-Bold")

PdfBox transform PDF with several pages to one Image JPG

余生颓废 提交于 2019-12-02 10:07:01
I have a pdf with several pages and I want to transform that to one Image. My actual code create an image by pdf's page... @Test public void testImage() throws IOException { try { PDDocument pdDocument = PDDocument.load(new File("download.pdf")); PDFRenderer pdfRenderer = new PDFRenderer(pdDocument); for (int x = 0; x < pdDocument.getNumberOfPages(); x++) { BufferedImage bImage = pdfRenderer.renderImageWithDPI(x, 300, ImageType.RGB); ImageIOUtil.writeImage(bImage, String.format(x +"__template_image.%s", "jpg"), 300); File imageFile = new File(x +"_template_image.jpg"); } pdDocument.close(); }

How to set the text of a PDTextbox to a color?

好久不见. 提交于 2019-12-02 09:49:29
I would like a PDTextbox to have Red text. I'm able to write out Red text, and I can set the value of a textbox, but I'm not sure how to set the textbox content to the color Red. ie. if (field instanceof PDTextbox) { field.setValue(field.getPartialName()); //SOME WAY TO SET COLOR HERE? Here is the test code I'm using: package com.circumail; import java.awt.Color; import java.io.File; import java.io.IOException; import java.util.List; import org.apache.fontbox.util.BoundingBox; import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos

Apache PDFBox: How can I specify the position of the texts I'm outputting

戏子无情 提交于 2019-12-02 09:34:23
So basically I already achieved creating a text when generating a pdf on a specific position. But now my problem is, how do I do it for text that are located on different positions Expected Generated PDF: contentStream.setLeading(15); contentStream.newLineAtOffset(175, 670); String text = "Text 1"; String text1 = "Text 2"; String text2 = "Text 3"; String text3 = "Text 4"; String text4 = "Text 5"; contentStream.showText(text); contentStream.newLine(); contentStream.showText(text1); contentStream.newLine(); contentStream.showText(text2); contentStream.newLine(); contentStream.showText(text3);

Rotate watermark text at 45 degree angle across the center Apache PDFBox

跟風遠走 提交于 2019-12-02 08:53:47
问题 I want to add a text to the PDF using PDFBox API and rotate it by 45 Degree and place it at the center of the page, The text is dynamic and should be placed in the center always, I got everything else to work except centering piece, I'll appreciate any help. I have this code: Point2D.Float pageCenter = getCenter(page); float stringWidth = getStringWidth(watermarkText, font, fontSize); float textX = pageCenter.x - stringWidth / 2F + center.x; System.out.println(textX); float textY = pageCenter

Java printing PDF with options (staple, duplex, etc)

喜夏-厌秋 提交于 2019-12-02 08:34:34
I have a java program that prints PDFs. It uses Apache PDFBox to create a PDDocument object (from a pdf document or from a stream in some cases) and then sends it to the printer using the javax.print API: private boolean print(File pdf, String printer) { boolean success = false; try (PDDocument document = PDDocument.load(pdf)) { PrintService[] printServices = PrinterJob.lookupPrintServices(); PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); // set printer if (printer != null) {

open PDF File with parameters

别说谁变了你拦得住时间么 提交于 2019-12-02 08:02:06
i am working on a java based tool, which should search for PDF files on selected directories and which should search for special words/sentences in this PDF files. After that a JList shows the files which fits and with a double-click on one of these entries the PDF Reader (Adobe Reader) should open this file directly on the page where the word/sentence appeares. I tried two different things. Runtime.exec: try{ Runtime.getRuntime().exec("rundll32" + " " + "url.dll,FileProtocolHandler /A page=4" + " " + o.toString()); }catch(IOException ex) { ex.printStackTrace(); } Desktop open: if(Desktop

Why some of the content is getting cropped off after resizing the page to 7.31 x 11 size?

隐身守侯 提交于 2019-12-02 07:58:07
When I am trying to resize the page to 7.31 x 11 , some of the content in that page is getting cropped off the window. Below is the link for my output document. http://www.filedropper.com/mynewdocument Below is my source code import java.awt.print.PrinterException; import java.io.File; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException; import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo; import org