com.lowagie.text.pdf.PdfDictionary Java Examples
The following examples show how to use
com.lowagie.text.pdf.PdfDictionary.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Image.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Reuses an existing image. * * @param ref the reference to the image dictionary * @throws BadElementException on error * @return the image */ public static Image getInstance(PRIndirectReference ref) throws BadElementException { PdfDictionary dic = (PdfDictionary) PdfReader.getPdfObjectRelease(ref); int width = ((PdfNumber) PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue(); int height = ((PdfNumber) PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue(); Image imask = null; PdfObject obj = dic.get(PdfName.SMASK); if (obj != null && obj.isIndirect()) { imask = getInstance((PRIndirectReference) obj); } else { obj = dic.get(PdfName.MASK); if (obj != null && obj.isIndirect()) { PdfObject obj2 = PdfReader.getPdfObjectRelease(obj); if (obj2 instanceof PdfDictionary) { imask = getInstance((PRIndirectReference) obj); } } } Image img = new ImgRaw(width, height, 1, 1, null); img.imageMask = imask; img.directReference = ref; return img; }
Example #2
Source File: PdfTextExtractor.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Gets the text from a page. * @param page the page number of the page * @return a String with the content as plain text (without PDF syntax) * @throws IOException */ public String getTextFromPage(int page) throws IOException { int totalPages = reader.getNumberOfPages(); if (totalPages < page) { throw new IOException("indicated page does not exists, requested page " + page + " document pages " + totalPages); } if (page <= 0) { throw new IOException("page number must be postive:" + page); } PdfDictionary pageDic = reader.getPageN(page); if (pageDic == null) { return ""; } PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES); extractionProcessor.processContent(getContentBytesForPage(page), resourcesDic); return extractionProcessor.getResultantText(); }
Example #3
Source File: Image.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Reuses an existing image. * @param ref the reference to the image dictionary * @throws BadElementException on error * @return the image */ public static Image getInstance(PRIndirectReference ref) throws BadElementException { PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref); int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue(); int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue(); Image imask = null; PdfObject obj = dic.get(PdfName.SMASK); if (obj != null && obj.isIndirect()) { imask = getInstance((PRIndirectReference)obj); } else { obj = dic.get(PdfName.MASK); if (obj != null && obj.isIndirect()) { PdfObject obj2 = PdfReader.getPdfObjectRelease(obj); if (obj2 instanceof PdfDictionary) imask = getInstance((PRIndirectReference)obj); } } Image img = new ImgRaw(width, height, 1, 1, null); img.imageMask = imask; img.directReference = ref; return img; }
Example #4
Source File: PdfContentStreamProcessor.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfName dictionaryName = (PdfName) operands.get(0); PdfDictionary extGState = processor.resources.getAsDict(PdfName.EXTGSTATE); if (extGState == null) { throw new IllegalArgumentException( "Resources do not contain ExtGState entry. Unable to process operator " + operator); } PdfDictionary gsDic = extGState.getAsDict(dictionaryName); if (gsDic == null) { throw new IllegalArgumentException(dictionaryName + " is an unknown graphics state dictionary"); } // at this point, all we care about is the FONT entry in the GS dictionary PdfArray fontParameter = gsDic.getAsArray(PdfName.FONT); if (fontParameter != null) { CMapAwareDocumentFont font = new CMapAwareDocumentFont( (PRIndirectReference) fontParameter.getPdfObject(0)); float size = fontParameter.getAsNumber(1).floatValue(); processor.gs().font = font; processor.gs().fontSize = size; } }
Example #5
Source File: PdfXConformanceImp.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
public void completeInfoDictionary(PdfDictionary info) { if (isPdfX() && !isPdfA1()) { if (info.get(PdfName.GTS_PDFXVERSION) == null) { if (isPdfX1A2001()) { info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-1:2001")); info.put(new PdfName("GTS_PDFXConformance"), new PdfString("PDF/X-1a:2001")); } else if (isPdfX32002()) info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-3:2002")); } if (info.get(PdfName.TITLE) == null) { info.put(PdfName.TITLE, new PdfString("Pdf document")); } if (info.get(PdfName.CREATOR) == null) { info.put(PdfName.CREATOR, new PdfString("Unknown")); } if (info.get(PdfName.TRAPPED) == null) { info.put(PdfName.TRAPPED, new PdfName("False")); } } }
Example #6
Source File: PdfXConformanceImp.java From gcs with Mozilla Public License 2.0 | 6 votes |
public void completeInfoDictionary(PdfDictionary info) { if (isPdfX() && !isPdfA1()) { if (info.get(PdfName.GTS_PDFXVERSION) == null) { if (isPdfX1A2001()) { info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-1:2001")); info.put(new PdfName("GTS_PDFXConformance"), new PdfString("PDF/X-1a:2001")); } else if (isPdfX32002()) info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-3:2002")); } if (info.get(PdfName.TITLE) == null) { info.put(PdfName.TITLE, new PdfString("Pdf document")); } if (info.get(PdfName.CREATOR) == null) { info.put(PdfName.CREATOR, new PdfString("Unknown")); } if (info.get(PdfName.TRAPPED) == null) { info.put(PdfName.TRAPPED, new PdfName("False")); } } }
Example #7
Source File: PdfGlyphRenderer.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void draw() { if (addActualText) { PdfDictionary markedContentProps = new PdfDictionary(); markedContentProps.put(PdfName.ACTUALTEXT, new PdfString(allText, PdfObject.TEXT_UNICODE)); pdfContentByte.beginMarkedContentSequence(PdfName.SPAN, markedContentProps, true); } TabSegment segment = segments.get(segmentIndex); segment.layout.draw( pdfGraphics2D, x + drawPosX,// + leftPadding, y + topPadding + verticalAlignOffset + drawPosY ); if (addActualText) { pdfContentByte.endMarkedContentSequence(); } return; }
Example #8
Source File: PdfContentStreamProcessor.java From gcs with Mozilla Public License 2.0 | 6 votes |
@Override public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfName dictionaryName = (PdfName) operands.get(0); PdfDictionary extGState = processor.resources.getAsDict(PdfName.EXTGSTATE); if (extGState == null) { throw new IllegalArgumentException("Resources do not contain ExtGState entry. Unable to process operator " + operator); } PdfDictionary gsDic = extGState.getAsDict(dictionaryName); if (gsDic == null) { throw new IllegalArgumentException(dictionaryName + " is an unknown graphics state dictionary"); } // at this point, all we care about is the FONT entry in the GS dictionary PdfArray fontParameter = gsDic.getAsArray(PdfName.FONT); if (fontParameter != null) { CMapAwareDocumentFont font = new CMapAwareDocumentFont((PRIndirectReference) fontParameter.getPdfObject(0)); float size = fontParameter.getAsNumber(1).floatValue(); processor.gs().font = font; processor.gs().fontSize = size; } }
Example #9
Source File: PdfContentStreamProcessor.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Processes PDF syntax * * @param contentBytes the bytes of a content stream * @param resources the resources that come with the content stream */ public void processContent(byte[] contentBytes, PdfDictionary resources) { reset(); this.resources = resources; try { PdfContentParser ps = new PdfContentParser(new PRTokeniser(contentBytes)); ArrayList operands = new ArrayList(); while (ps.parse(operands).size() > 0) { PdfLiteral operator = (PdfLiteral) operands.get(operands.size() - 1); invokeOperator(operator, operands); } } catch (Exception e) { throw new ExceptionConverter(e); } }
Example #10
Source File: Prd5873Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
private void runTest(MasterReport report) throws ResourceException, ReportProcessingException, IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); PdfReportUtil.createPDF(report, bout); PdfReader reader = new PdfReader(bout.toByteArray()); printPdfPage(reader); final PdfDictionary pageN = reader.getPageN(1); final PdfDictionary asDict = pageN.getAsDict(PdfName.RESOURCES); final byte[] pageContent = reader.getPageContent(1); PdfValidator pv = new PdfValidator(); pv.processContent(pageContent, asDict); }
Example #11
Source File: PdfViewerPreferencesImp.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Adds the viewer preferences defined in the preferences parameter to a * PdfDictionary (more specifically the root or catalog of a PDF file). * * @param catalog */ public void addToCatalog(PdfDictionary catalog) { // Page Layout catalog.remove(PdfName.PAGELAYOUT); if ((pageLayoutAndMode & PdfWriter.PageLayoutSinglePage) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.SINGLEPAGE); else if ((pageLayoutAndMode & PdfWriter.PageLayoutOneColumn) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.ONECOLUMN); else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoColumnLeft) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNLEFT); else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoColumnRight) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNRIGHT); else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoPageLeft) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.TWOPAGELEFT); else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoPageRight) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.TWOPAGERIGHT); // Page Mode catalog.remove(PdfName.PAGEMODE); if ((pageLayoutAndMode & PdfWriter.PageModeUseNone) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USENONE); else if ((pageLayoutAndMode & PdfWriter.PageModeUseOutlines) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USEOUTLINES); else if ((pageLayoutAndMode & PdfWriter.PageModeUseThumbs) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USETHUMBS); else if ((pageLayoutAndMode & PdfWriter.PageModeFullScreen) != 0) catalog.put(PdfName.PAGEMODE, PdfName.FULLSCREEN); else if ((pageLayoutAndMode & PdfWriter.PageModeUseOC) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USEOC); else if ((pageLayoutAndMode & PdfWriter.PageModeUseAttachments) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USEATTACHMENTS); // viewer preferences (Table 8.1 of the PDF Reference) catalog.remove(PdfName.VIEWERPREFERENCES); if (viewerPreferences.size() > 0) { catalog.put(PdfName.VIEWERPREFERENCES, viewerPreferences); } }
Example #12
Source File: BmpImage.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
private Image indexedModel(byte bdata[], int bpc, int paletteEntries) throws BadElementException { Image img = new ImgRaw(width, height, 1, bpc, bdata); PdfArray colorspace = new PdfArray(); colorspace.add(PdfName.INDEXED); colorspace.add(PdfName.DEVICERGB); byte np[] = getPalette(paletteEntries); int len = np.length; colorspace.add(new PdfNumber(len / 3 - 1)); colorspace.add(new PdfString(np)); PdfDictionary ad = new PdfDictionary(); ad.put(PdfName.COLORSPACE, colorspace); img.setAdditional(ad); return img; }
Example #13
Source File: PdfXConformanceImp.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
public void completeExtraCatalog(PdfDictionary extraCatalog) { if (isPdfX() && !isPdfA1()) { if (extraCatalog.get(PdfName.OUTPUTINTENTS) == null) { PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT); out.put(PdfName.OUTPUTCONDITION, new PdfString("SWOP CGATS TR 001-1995")); out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("CGATS TR 001")); out.put(PdfName.REGISTRYNAME, new PdfString("http://www.color.org")); out.put(PdfName.INFO, new PdfString("")); out.put(PdfName.S, PdfName.GTS_PDFX); extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out)); } } }
Example #14
Source File: PdfVersionImp.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** Adds the version to the Catalog dictionary. */ public void addToCatalog(PdfDictionary catalog) { if(catalog_version != null) { catalog.put(PdfName.VERSION, catalog_version); } if (extensions != null) { catalog.put(PdfName.EXTENSIONS, extensions); } }
Example #15
Source File: PdfContentStreamProcessorTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
private void processBytes(final byte[] pdfBytes, final int pageNumber) throws IOException { final PdfReader pdfReader = new PdfReader(pdfBytes); final PdfDictionary pageDictionary = pdfReader.getPageN(pageNumber); final PdfDictionary resourceDictionary = pageDictionary.getAsDict(PdfName.RESOURCES); final PdfObject contentObject = pageDictionary.get(PdfName.CONTENTS); final byte[] contentBytes = readContentBytes(contentObject); _processor.processContent(contentBytes, resourceDictionary); }
Example #16
Source File: PdfContentStreamProcessor.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfName fontResourceName = (PdfName) operands.get(0); float size = ((PdfNumber) operands.get(1)).floatValue(); PdfDictionary fontsDictionary = processor.resources.getAsDict(PdfName.FONT); CMapAwareDocumentFont font = new CMapAwareDocumentFont( (PRIndirectReference) fontsDictionary.get(fontResourceName)); processor.gs().font = font; processor.gs().fontSize = size; }
Example #17
Source File: PdfContentStreamProcessor.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
@Override public PdfObject getDirectObject(PdfName key) { for (int i = stack.size() - 1; i >= 0; i--) { PdfDictionary dict = stack.get(i); PdfObject o = dict.getDirectObject(key); if (o != null) { return o; } } return null; }
Example #18
Source File: JRPdfExporterTagHelper.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected void startText(String text, boolean isHyperlink) { if (isTagged) { PdfDictionary markedContentProps = new PdfDictionary(); markedContentProps.put(PdfName.ACTUALTEXT, new PdfString(text, PdfObject.TEXT_UNICODE)); PdfStructureElement textTag = new PdfStructureElement(tagStack.peek(), isHyperlink ? PdfName.LINK : PdfName.TEXT); // the following method is part of the patched iText pdfContentByte.beginMarkedContentSequence(textTag, markedContentProps); } }
Example #19
Source File: PdfCollectionItem.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Adds a prefix for the Collection item. * You can only use this method after you have set the value of the item. * @param prefix a prefix */ public void setPrefix(String key, String prefix) { PdfName fieldname = new PdfName(key); PdfObject o = get(fieldname); if (o == null) throw new IllegalArgumentException("You must set a value before adding a prefix."); PdfDictionary dict = new PdfDictionary(PdfName.COLLECTIONSUBITEM); dict.put(PdfName.D, o); dict.put(PdfName.P, new PdfString(prefix, PdfObject.TEXT_UNICODE)); put(fieldname, dict); }
Example #20
Source File: PdfContentStreamProcessor.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Processes PDF syntax * @param contentBytes the bytes of a content stream * @param resources the resources that come with the content stream */ public void processContent(byte[] contentBytes, PdfDictionary resources) { this.resources.push(resources); try { PdfContentParser ps = new PdfContentParser(new PRTokeniser(contentBytes)); ArrayList operands = new ArrayList(); while (ps.parse(operands).size() > 0) { PdfLiteral operator = (PdfLiteral) operands.get(operands.size() - 1); invokeOperator(operator, operands); } } catch (Exception e) { throw new ExceptionConverter(e); } this.resources.pop(); }
Example #21
Source File: PdfContentReaderTool.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Writes information about a specific page from PdfReader to the specified output stream. * @since 2.1.5 * @param reader the PdfReader to read the page content from * @param pageNum the page number to read * @param out the output stream to send the content to * @throws IOException */ static public void listContentStreamForPage(PdfReader reader, int pageNum, PrintWriter out) throws IOException { out.println("==============Page " + pageNum + "===================="); out.println("- - - - - Dictionary - - - - - -"); PdfDictionary pageDictionary = reader.getPageN(pageNum); out.println(getDictionaryDetail(pageDictionary)); out.println("- - - - - Content Stream - - - - - -"); RandomAccessFileOrArray f = reader.getSafeFile(); byte[] contentBytes = reader.getPageContent(pageNum, f); f.close(); InputStream is = new ByteArrayInputStream(contentBytes); int ch; while ((ch = is.read()) != -1){ out.print((char)ch); } out.println("- - - - - Text Extraction - - - - - -"); PdfTextExtractor extractor = new PdfTextExtractor(reader); String extractedText = extractor.getTextFromPage(pageNum); if (extractedText.length() != 0) out.println(extractedText); else out.println("No text found on page " + pageNum); out.println(); }
Example #22
Source File: ITextPDFSignatureService.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
private PdfDictionary findExistingSignature(PdfReader reader, String signatureFieldId) { AcroFields acroFields = reader.getAcroFields(); List<String> signatureNames = acroFields.getFieldNamesWithBlankSignatures(); if (signatureNames.contains(signatureFieldId)) { Item item = acroFields.getFieldItem(signatureFieldId); return item.getMerged(0); } throw new DSSException("The signature field '" + signatureFieldId + "' does not exist."); }
Example #23
Source File: ITextPDFSignatureService.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public DSSDocument sign(DSSDocument toSignDocument, byte[] signatureValue, PAdESCommonParameters parameters) { checkDocumentPermissions(toSignDocument, parameters.getPasswordProtection()); try (InputStream is = toSignDocument.openStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream()) { PdfStamper stp = prepareStamper(is, baos, parameters); PdfSignatureAppearance sap = stp.getSignatureAppearance(); byte[] pk = signatureValue; int csize = parameters.getContentSize(); if (csize < pk.length) { throw new DSSException( String.format("The signature size [%s] is too small for the signature value with a length [%s]", csize, pk.length)); } byte[] outc = new byte[csize]; System.arraycopy(pk, 0, outc, 0, pk.length); PdfDictionary dic = new PdfDictionary(); dic.put(PdfName.CONTENTS, new PdfString(outc).setHexWriting(true)); sap.close(dic); DSSDocument signature = new InMemoryDocument(baos.toByteArray()); signature.setMimeType(MimeType.PDF); return signature; } catch (Exception e) { throw new DSSException(e); } }
Example #24
Source File: PdfCollectionItem.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Adds a prefix for the Collection item. * You can only use this method after you have set the value of the item. * @param prefix a prefix */ public void setPrefix(String key, String prefix) { PdfName fieldname = new PdfName(key); PdfObject o = get(fieldname); if (o == null) throw new IllegalArgumentException("You must set a value before adding a prefix."); PdfDictionary dict = new PdfDictionary(PdfName.COLLECTIONSUBITEM); dict.put(PdfName.D, o); dict.put(PdfName.P, new PdfString(prefix, PdfObject.TEXT_UNICODE)); put(fieldname, dict); }
Example #25
Source File: BmpImage.java From gcs with Mozilla Public License 2.0 | 5 votes |
private Image indexedModel(byte bdata[], int bpc, int paletteEntries) throws BadElementException { Image img = new ImgRaw(width, height, 1, bpc, bdata); PdfArray colorspace = new PdfArray(); colorspace.add(PdfName.INDEXED); colorspace.add(PdfName.DEVICERGB); byte np[] = getPalette(paletteEntries); int len = np.length; colorspace.add(new PdfNumber(len / 3 - 1)); colorspace.add(new PdfString(np)); PdfDictionary ad = new PdfDictionary(); ad.put(PdfName.COLORSPACE, colorspace); img.setAdditional(ad); return img; }
Example #26
Source File: PdfViewerPreferencesImp.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Adds the viewer preferences defined in the preferences parameter to a * PdfDictionary (more specifically the root or catalog of a PDF file). * * @param catalog */ public void addToCatalog(PdfDictionary catalog) { // Page Layout catalog.remove(PdfName.PAGELAYOUT); if ((pageLayoutAndMode & PdfWriter.PageLayoutSinglePage) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.SINGLEPAGE); else if ((pageLayoutAndMode & PdfWriter.PageLayoutOneColumn) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.ONECOLUMN); else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoColumnLeft) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNLEFT); else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoColumnRight) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNRIGHT); else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoPageLeft) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.TWOPAGELEFT); else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoPageRight) != 0) catalog.put(PdfName.PAGELAYOUT, PdfName.TWOPAGERIGHT); // Page Mode catalog.remove(PdfName.PAGEMODE); if ((pageLayoutAndMode & PdfWriter.PageModeUseNone) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USENONE); else if ((pageLayoutAndMode & PdfWriter.PageModeUseOutlines) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USEOUTLINES); else if ((pageLayoutAndMode & PdfWriter.PageModeUseThumbs) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USETHUMBS); else if ((pageLayoutAndMode & PdfWriter.PageModeFullScreen) != 0) catalog.put(PdfName.PAGEMODE, PdfName.FULLSCREEN); else if ((pageLayoutAndMode & PdfWriter.PageModeUseOC) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USEOC); else if ((pageLayoutAndMode & PdfWriter.PageModeUseAttachments) != 0) catalog.put(PdfName.PAGEMODE, PdfName.USEATTACHMENTS); // viewer preferences (Table 8.1 of the PDF Reference) catalog.remove(PdfName.VIEWERPREFERENCES); if (viewerPreferences.size() > 0) { catalog.put(PdfName.VIEWERPREFERENCES, viewerPreferences); } }
Example #27
Source File: ITextPdfDict.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public PdfDict getAsDict(String name) { PdfDictionary asDict = wrapped.getAsDict(new PdfName(name)); if (asDict == null) { return null; } else { return new ITextPdfDict(asDict); } }
Example #28
Source File: PaperightPdfConverter.java From website with GNU Affero General Public License v3.0 | 5 votes |
public String cropPdf(String pdfFilePath) throws DocumentException, IOException, Exception { String filename = FilenameUtils.getBaseName(pdfFilePath) + "_cropped." + FilenameUtils.getExtension(pdfFilePath); filename = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), filename); PdfReader reader = new PdfReader(pdfFilePath); try { PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(filename)); try { for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfDictionary pdfDictionary = reader.getPageN(i); PdfArray cropArray = new PdfArray(); Rectangle box = getSmallestBox(reader, i); //Rectangle cropbox = reader.getCropBox(i); if (box != null) { cropArray.add(new PdfNumber(box.getLeft())); cropArray.add(new PdfNumber(box.getBottom())); cropArray.add(new PdfNumber(box.getLeft() + box.getWidth())); cropArray.add(new PdfNumber(box.getBottom() + box.getHeight())); pdfDictionary.put(PdfName.CROPBOX, cropArray); pdfDictionary.put(PdfName.MEDIABOX, cropArray); pdfDictionary.put(PdfName.TRIMBOX, cropArray); pdfDictionary.put(PdfName.BLEEDBOX, cropArray); } } return filename; } finally { stamper.close(); } } catch (Exception e) { logger.error(e.getMessage(), e); throw e; } finally { reader.close(); } }
Example #29
Source File: PdfXConformanceImp.java From gcs with Mozilla Public License 2.0 | 5 votes |
public void completeExtraCatalog(PdfDictionary extraCatalog) { if (isPdfX() && !isPdfA1()) { if (extraCatalog.get(PdfName.OUTPUTINTENTS) == null) { PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT); out.put(PdfName.OUTPUTCONDITION, new PdfString("SWOP CGATS TR 001-1995")); out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("CGATS TR 001")); out.put(PdfName.REGISTRYNAME, new PdfString("http://www.color.org")); out.put(PdfName.INFO, new PdfString("")); out.put(PdfName.S, PdfName.GTS_PDFX); extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out)); } } }
Example #30
Source File: PdfVersionImp.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** Adds the version to the Catalog dictionary. */ public void addToCatalog(PdfDictionary catalog) { if(catalog_version != null) { catalog.put(PdfName.VERSION, catalog_version); } if (extensions != null) { catalog.put(PdfName.EXTENSIONS, extensions); } }