Java Code Examples for com.lowagie.text.pdf.PdfName
The following examples show how to use
com.lowagie.text.pdf.PdfName.
These examples are extracted from open source projects.
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 Project: itext2 Author: albfernandez File: FieldPositioningEvents.java License: 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 Project: gcs Author: richardwilkes File: PdfContentStreamProcessor.java License: 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 #3
Source Project: gcs Author: richardwilkes File: PdfXConformanceImp.java License: 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 #4
Source Project: gcs Author: richardwilkes File: PdfCollectionSort.java License: 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 #5
Source Project: itext2 Author: albfernandez File: Image.java License: 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 #6
Source Project: itext2 Author: albfernandez File: PdfTextExtractor.java License: 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 #7
Source Project: itext2 Author: albfernandez File: PdfVersionImp.java License: 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 #8
Source Project: itext2 Author: albfernandez File: PdfCollectionItem.java License: GNU Lesser General Public License v3.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 #9
Source Project: gcs Author: richardwilkes File: Image.java License: 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); }
Example #10
Source Project: gcs Author: richardwilkes File: PdfTextExtractor.java License: Mozilla Public License 2.0 | 5 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 { PdfDictionary pageDic = reader.getPageN(page); PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES); extractionProcessor.processContent(getContentBytesForPage(page), resourcesDic); return extractionProcessor.getResultantText(); }
Example #11
Source Project: dss Author: esig File: ITextPdfDict.java License: GNU Lesser General Public License v2.1 | 5 votes |
@Override public String getStringValue(String key) { PdfString pdfString = wrapped.getAsString(new PdfName(key)); if (pdfString == null) { return null; } else { return pdfString.toUnicodeString(); } }
Example #12
Source Project: gcs Author: richardwilkes File: PdfVersionImp.java License: 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); } }
Example #13
Source Project: gcs Author: richardwilkes File: PdfXConformanceImp.java License: 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 #14
Source Project: gcs Author: richardwilkes File: PdfViewerPreferencesImp.java License: Mozilla Public License 2.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 #15
Source Project: gcs Author: richardwilkes File: PdfViewerPreferencesImp.java License: Mozilla Public License 2.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 #16
Source Project: jasperreports Author: TIBCOSoftware File: JRPdfExporterTagHelper.java License: GNU Lesser General Public License v3.0 | 5 votes |
protected void createListItemStartTag(JRPrintElement element) { PdfStructureElement listItemTag = new PdfStructureElement(tagStack.peek(), PdfName.LI); //pdfContentByte.beginMarkedContentSequence(tableHeaderTag); listItemTag.put(PdfName.K, new PdfArray()); tagStack.push(listItemTag); isTagEmpty = true; }
Example #17
Source Project: jasperreports Author: TIBCOSoftware File: JRPdfExporterTagHelper.java License: GNU Lesser General Public License v3.0 | 5 votes |
protected void createTableStartTag() { PdfStructureElement tableTag = new PdfStructureElement(allTag, PdfName.TABLE); //pdfContentByte.beginMarkedContentSequence(tableTag); tableTag.put(PdfName.K, new PdfArray()); tagStack.push(tableTag); }
Example #18
Source Project: jasperreports Author: TIBCOSoftware File: JRPdfExporterTagHelper.java License: GNU Lesser General Public License v3.0 | 5 votes |
protected void createStartHeadingTags(String prop, PdfName pdfName) { if (TAG_START.equals(prop) || TAG_FULL.equals(prop)) { PdfStructureElement headingTag = new PdfStructureElement(tagStack.peek(), pdfName); //pdfContentByte.beginMarkedContentSequence(headingTag); headingTag.put(PdfName.K, new PdfArray()); tagStack.push(headingTag); isTagEmpty = true; } }
Example #19
Source Project: gcs Author: richardwilkes File: PdfCollectionField.java License: Mozilla Public License 2.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 #20
Source Project: itext2 Author: albfernandez File: PdfTargetDictionary.java License: 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 #21
Source Project: jasperreports Author: TIBCOSoftware File: JRPdfExporterTagHelper.java License: 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 #22
Source Project: dss Author: esig File: ITextPdfDict.java License: 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 #23
Source Project: gcs Author: richardwilkes File: PdfCollectionItem.java License: 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 #24
Source Project: gcs Author: richardwilkes File: PdfCollectionItem.java License: 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 #25
Source Project: gcs Author: richardwilkes File: PdfCollectionItem.java License: 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 Project: gcs Author: richardwilkes File: PdfCollectionItem.java License: 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 #27
Source Project: openbd-core Author: OpenBD File: cfDOCUMENT.java License: 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 #28
Source Project: itext2 Author: albfernandez File: PdfCollectionField.java License: 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 #29
Source Project: dss Author: esig File: ITextPdfDict.java License: 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 #30
Source Project: jasperreports Author: TIBCOSoftware File: JRPdfExporterTagHelper.java License: 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); }