com.lowagie.text.pdf.PdfName Java Examples
The following examples show how to use
com.lowagie.text.pdf.PdfName.
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: FieldPositioningEvents.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String) */ public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) { rect.setBottom(rect.getBottom() - 3); PdfFormField field = (PdfFormField) genericChunkFields.get(text); if (field == null) { TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text); tf.setFontSize(14); try { field = tf.getTextField(); } catch (Exception e) { throw new ExceptionConverter(e); } } else { field.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding))); } if (parent == null) writer.addAnnotation(field); else parent.addKid(field); }
Example #2
Source File: PdfCollectionSort.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Defines the sort order of the field (ascending or descending). * @param ascending an array with every element corresponding with a name of a field. */ public void setSortOrder(boolean[] ascending) { PdfObject o = get(PdfName.S); if (o instanceof PdfArray) { if (((PdfArray)o).size() != ascending.length) { throw new IllegalArgumentException("The number of booleans in this array doesn't correspond with the number of fields."); } PdfArray array = new PdfArray(); for (int i = 0; i < ascending.length; i++) { array.add(new PdfBoolean(ascending[i])); } put(PdfName.A, array); } else { throw new IllegalArgumentException("You need a single boolean for this collection sort dictionary."); } }
Example #3
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 #4
Source File: Image.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. */ public void simplifyColorspace() { if (additional == null) return; PdfArray value = additional.getAsArray(PdfName.COLORSPACE); if (value == null) return; PdfObject cs = simplifyColorspace(value); PdfObject newValue; if (cs.isName()) newValue = cs; else { newValue = value; PdfName first = value.getAsName(0); if (PdfName.INDEXED.equals(first)) { if (value.size() >= 2) { PdfArray second = value.getAsArray(1); if (second != null) { value.set(1, simplifyColorspace(second)); } } } } additional.put(PdfName.COLORSPACE, newValue); }
Example #5
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 #6
Source File: PdfVersionImp.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns the PDF version as a name. * @param version the version character. */ public PdfName getVersionAsName(char version) { switch(version) { case PdfWriter.VERSION_1_2: return PdfWriter.PDF_VERSION_1_2; case PdfWriter.VERSION_1_3: return PdfWriter.PDF_VERSION_1_3; case PdfWriter.VERSION_1_4: return PdfWriter.PDF_VERSION_1_4; case PdfWriter.VERSION_1_5: return PdfWriter.PDF_VERSION_1_5; case PdfWriter.VERSION_1_6: return PdfWriter.PDF_VERSION_1_6; case PdfWriter.VERSION_1_7: return PdfWriter.PDF_VERSION_1_7; default: return PdfWriter.PDF_VERSION_1_4; } }
Example #7
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 #8
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 #9
Source File: ITextPdfDict.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public byte[] getBinariesValue(String name) { PdfObject val = wrapped.get(new PdfName(name)); if (val == null) { return null; } else if (val instanceof PdfString) { PdfString pdfString = (PdfString) val; return pdfString.getOriginalBytes(); } return val.getBytes(); }
Example #10
Source File: ITextPdfDict.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public String getNameValue(String key) { PdfName pdfName = wrapped.getAsName(new PdfName(key)); if (pdfName == null) { return null; } else { return PdfName.decodeName(pdfName.toString()); } }
Example #11
Source File: PdfTargetDictionary.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a dictionary referring to a target document. * @param child if false, this refers to the parent document; if true, this refers to a child document, and you'll have to specify where to find the child using the other methods of this class */ public PdfTargetDictionary(boolean child) { super(); if (child) { put(PdfName.R, PdfName.C); } else { put(PdfName.R, PdfName.P); } }
Example #12
Source File: PdfViewerPreferencesImp.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Given a key for a viewer preference (a PdfName object), * this method returns the index in the VIEWER_PREFERENCES array. * @param key a PdfName referring to a viewer preference * @return an index in the VIEWER_PREFERENCES array */ private int getIndex(PdfName key) { for (int i = 0; i < VIEWER_PREFERENCES.length; i++) { if (VIEWER_PREFERENCES[i].equals(key)) return i; } return -1; }
Example #13
Source File: PdfViewerPreferencesImp.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sets the viewer preferences as the sum of several constants. * * @param preferences * the viewer preferences * @see PdfViewerPreferences#setViewerPreferences */ public void setViewerPreferences(int preferences) { this.pageLayoutAndMode |= preferences; // for backwards compatibility, it is also possible // to set the following viewer preferences with this method: if ((preferences & viewerPreferencesMask) != 0) { pageLayoutAndMode = ~viewerPreferencesMask & pageLayoutAndMode; if ((preferences & PdfWriter.HideToolbar) != 0) viewerPreferences.put(PdfName.HIDETOOLBAR, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.HideMenubar) != 0) viewerPreferences.put(PdfName.HIDEMENUBAR, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.HideWindowUI) != 0) viewerPreferences.put(PdfName.HIDEWINDOWUI, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.FitWindow) != 0) viewerPreferences.put(PdfName.FITWINDOW, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.CenterWindow) != 0) viewerPreferences.put(PdfName.CENTERWINDOW, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.DisplayDocTitle) != 0) viewerPreferences.put(PdfName.DISPLAYDOCTITLE, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.NonFullScreenPageModeUseNone) != 0) viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USENONE); else if ((preferences & PdfWriter.NonFullScreenPageModeUseOutlines) != 0) viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USEOUTLINES); else if ((preferences & PdfWriter.NonFullScreenPageModeUseThumbs) != 0) viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USETHUMBS); else if ((preferences & PdfWriter.NonFullScreenPageModeUseOC) != 0) viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USEOC); if ((preferences & PdfWriter.DirectionL2R) != 0) viewerPreferences.put(PdfName.DIRECTION, PdfName.L2R); else if ((preferences & PdfWriter.DirectionR2L) != 0) viewerPreferences.put(PdfName.DIRECTION, PdfName.R2L); if ((preferences & PdfWriter.PrintScalingNone) != 0) viewerPreferences.put(PdfName.PRINTSCALING, PdfName.NONE); } }
Example #14
Source File: JRPdfExporterTagHelper.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected void createTrStartTag() { PdfStructureElement tableRowTag = new PdfStructureElement(tagStack.peek(), PdfName.TABLEROW); //pdfContentByte.beginMarkedContentSequence(tableRowTag); tableRowTag.put(PdfName.K, new PdfArray()); tagStack.push(tableRowTag); }
Example #15
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 #16
Source File: PdfLogicalPageDrawable.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
protected void drawImageMap( final RenderableReplacedContentBox content ) { if ( version < '6' ) { return; } final ImageMap imageMap = RenderUtility.extractImageMap( content ); // only generate a image map, if the user does not specify their own onw via the override. // Of course, they would have to provide the map by other means as well. if ( imageMap == null ) { return; } final ImageMapEntry[] imageMapEntries = imageMap.getMapEntries(); for ( int i = 0; i < imageMapEntries.length; i++ ) { final ImageMapEntry imageMapEntry = imageMapEntries[i]; final String link = imageMapEntry.getAttribute( LibXmlInfo.XHTML_NAMESPACE, "href" ); final String tooltip = imageMapEntry.getAttribute( LibXmlInfo.XHTML_NAMESPACE, "title" ); if ( StringUtils.isEmpty( tooltip ) ) { continue; } final AffineTransform affineTransform = getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final int x = (int) ( translateX + StrictGeomUtility.toExternalValue( content.getX() ) ); final int y = (int) StrictGeomUtility.toExternalValue( content.getY() ); final float[] translatedCoords = translateCoordinates( imageMapEntry.getAreaCoordinates(), x, y ); final PolygonAnnotation polygonAnnotation = new PolygonAnnotation( writer, translatedCoords ); polygonAnnotation.put( PdfName.CONTENTS, new PdfString( tooltip, PdfObject.TEXT_UNICODE ) ); writer.addAnnotation( polygonAnnotation ); } }
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: 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 #19
Source File: PdfTargetDictionary.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates dictionary referring to a target document that is the parent of the current document. * @param nested null if this is the actual target, another target if this is only an intermediate target. */ public PdfTargetDictionary(PdfTargetDictionary nested) { super(); put(PdfName.R, PdfName.P); if (nested != null) setAdditionalPath(nested); }
Example #20
Source File: JRPdfExporterTagHelper.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected void createTdStartTag(JRPrintElement element) { PdfStructureElement tableCellTag = new PdfStructureElement(tagStack.peek(), PdfName.TD); //pdfContentByte.beginMarkedContentSequence(tableCellTag); tableCellTag.put(PdfName.K, new PdfArray()); tagStack.push(tableCellTag); isTagEmpty = true; createSpanTags(element, tableCellTag); }
Example #21
Source File: ITextPdfDict.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public PdfArray getAsArray(String name) { com.lowagie.text.pdf.PdfArray asArray = wrapped.getAsArray(new PdfName( name)); if (asArray == null) { return null; } else { return new ITextPdfArray(asArray); } }
Example #22
Source File: PdfCollectionField.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a PdfCollectionField. * @param name the field name * @param type the field type */ public PdfCollectionField(String name, int type) { super(PdfName.COLLECTIONFIELD); put(PdfName.N, new PdfString(name, PdfObject.TEXT_UNICODE)); this.fieldType = type; switch(type) { default: put(PdfName.SUBTYPE, PdfName.S); break; case DATE: put(PdfName.SUBTYPE, PdfName.D); break; case NUMBER: put(PdfName.SUBTYPE, PdfName.N); break; case FILENAME: put(PdfName.SUBTYPE, PdfName.F); break; case DESC: put(PdfName.SUBTYPE, PdfName.DESC); break; case MODDATE: put(PdfName.SUBTYPE, PdfName.MODDATE); break; case CREATIONDATE: put(PdfName.SUBTYPE, PdfName.CREATIONDATE); break; case SIZE: put(PdfName.SUBTYPE, PdfName.SIZE); break; } }
Example #23
Source File: cfDOCUMENT.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public void onClose(ITextRenderer renderer) { PdfString creator = new PdfString("OpenBD " + cfEngine.PRODUCT_VERSION + " (" + cfEngine.BUILD_ISSUE + ")"); renderer.getOutputDevice().getWriter().getInfo().put(PdfName.CREATOR,creator); if (author != null) renderer.getOutputDevice().getWriter().getInfo().put(PdfName.AUTHOR,author); if (title != null) renderer.getOutputDevice().getWriter().getInfo().put(PdfName.TITLE,title); if (subject != null) renderer.getOutputDevice().getWriter().getInfo().put(PdfName.SUBJECT,subject); if (keywords != null) renderer.getOutputDevice().getWriter().getInfo().put(PdfName.KEYWORDS,keywords); }
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: PdfCollectionItem.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Sets the value of the collection item. * @param n */ public void addItem(String key, PdfNumber n) { PdfName fieldname = new PdfName(key); PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); if (field.fieldType == PdfCollectionField.NUMBER) { put(fieldname, n); } }
Example #26
Source File: PdfCollectionItem.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Sets the value of the collection item. * @param d */ public void addItem(String key, PdfDate d) { PdfName fieldname = new PdfName(key); PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); if (field.fieldType == PdfCollectionField.DATE) { put(fieldname, d); } }
Example #27
Source File: PdfCollectionItem.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Sets the value of the collection item. * @param value */ public void addItem(String key, PdfString value) { PdfName fieldname = new PdfName(key); PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); if (field.fieldType == PdfCollectionField.TEXT) { put(fieldname, value); } }
Example #28
Source File: ITextPdfDict.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public String[] list() { Set<PdfName> keyPdfNames = wrapped.getKeys(); String[] keys = new String[keyPdfNames.size()]; PdfName[] array = keyPdfNames.toArray(new PdfName[keyPdfNames.size()]); for (int i = 0; i < array.length; i++) { keys[i] = PdfName.decodeName(array[i].toString()); } return keys; }
Example #29
Source File: JRPdfExporterTagHelper.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected void createEndHeadingTags(String prop) { if (TAG_END.equals(prop) || TAG_FULL.equals(prop)) { //pdfContentByte.endMarkedContentSequence(); if (isTagEmpty) { pdfContentByte.beginMarkedContentSequence(new PdfStructureElement(tagStack.peek(), PdfName.SPAN)); pdfContentByte.endMarkedContentSequence(); } tagStack.pop(); } }
Example #30
Source File: Image.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. */ public void simplifyColorspace() { if (additional == null) { return; } PdfArray value = additional.getAsArray(PdfName.COLORSPACE); if (value == null) { return; } PdfObject cs = simplifyColorspace(value); PdfObject newValue; if (cs.isName()) { newValue = cs; } else { newValue = value; PdfName first = value.getAsName(0); if (PdfName.INDEXED.equals(first)) { if (value.size() >= 2) { PdfArray second = value.getAsArray(1); if (second != null) { value.set(1, simplifyColorspace(second)); } } } } additional.put(PdfName.COLORSPACE, newValue); }