public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfNumber aw = (PdfNumber) operands.get(0); PdfNumber ac = (PdfNumber) operands.get(1); PdfString string = (PdfString) operands.get(2); ArrayList twOperands = new ArrayList(1); twOperands.add(0, aw); processor.invokeOperator(new PdfLiteral("Tw"), twOperands); ArrayList tcOperands = new ArrayList(1); tcOperands.add(0, ac); processor.invokeOperator(new PdfLiteral("Tc"), tcOperands); ArrayList tickOperands = new ArrayList(1); tickOperands.add(0, string); processor.invokeOperator(new PdfLiteral("'"), tickOperands); }
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")); } } }
/** * 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); }
@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; }
public PdfAttachment unpackFile(PdfDictionary filespec) throws IOException { if (filespec == null) return null; PdfName type = filespec.getAsName(PdfName.TYPE); if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type)) return null; PdfDictionary ef = filespec.getAsDict(PdfName.EF); if (ef == null) return null; PRStream prs = (PRStream)PdfReader.getPdfObject(ef.get(PdfName.F)); if (prs == null) return null; PdfString pdfDesc = filespec.getAsString(PdfName.DESC); String desc = pdfDesc != null ? pdfDesc.toString() : ""; PdfString pdfName = filespec.getAsString(PdfName.F); String name = pdfName != null ? pdfName.toString() : ""; byte[] data = PdfReader.getStreamBytes(prs); return new PdfAttachment(name, desc, data); }
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfNumber aw = (PdfNumber)operands.get(0); PdfNumber ac = (PdfNumber)operands.get(1); PdfString string = (PdfString)operands.get(2); ArrayList twOperands = new ArrayList(1); twOperands.add(0, aw); processor.invokeOperator(new PdfLiteral("Tw"), twOperands); ArrayList tcOperands = new ArrayList(1); tcOperands.add(0, ac); processor.invokeOperator(new PdfLiteral("Tc"), tcOperands); ArrayList tickOperands = new ArrayList(1); tickOperands.add(0, string); processor.invokeOperator(new PdfLiteral("'"), tickOperands); }
/** * Displays text. * @param string the text to display * @param tj the text adjustment */ public void displayPdfString(PdfString string, float tj) { String unicode = decode(string); // this is width in unscaled units - we have to normalize by the Tm scaling float width = getStringWidth(unicode, tj); Matrix nextTextMatrix = new Matrix(width, 0).multiply(textMatrix); displayText(unicode, nextTextMatrix); textMatrix = nextTextMatrix; }
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfArray array = (PdfArray) operands.get(0); float tj = 0; for (Iterator i = array.listIterator(); i.hasNext();) { Object entryObj = i.next(); if (entryObj instanceof PdfString) { processor.displayPdfString((PdfString) entryObj, tj); tj = 0; } else { tj = ((PdfNumber) entryObj).floatValue(); } } }
public static PdfAnnotation convertAnnotation(PdfWriter writer, Annotation annot, Rectangle defaultRect) throws IOException { switch(annot.annotationType()) { case Annotation.URL_NET: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((URL) annot.attributes().get(Annotation.URL))); case Annotation.URL_AS_STRING: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE))); case Annotation.FILE_DEST: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE), (String) annot.attributes().get(Annotation.DESTINATION))); case Annotation.SCREEN: boolean sparams[] = (boolean[])annot.attributes().get(Annotation.PARAMETERS); String fname = (String) annot.attributes().get(Annotation.FILE); String mimetype = (String) annot.attributes().get(Annotation.MIMETYPE); PdfFileSpecification fs; if (sparams[0]) fs = PdfFileSpecification.fileEmbedded(writer, fname, fname, null); else fs = PdfFileSpecification.fileExtern(writer, fname); PdfAnnotation ann = PdfAnnotation.createScreen(writer, new Rectangle(annot.llx(), annot.lly(), annot.urx(), annot.ury()), fname, fs, mimetype, sparams[1]); return ann; case Annotation.FILE_PAGE: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE), ((Integer) annot.attributes().get(Annotation.PAGE)).intValue())); case Annotation.NAMED_DEST: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction(((Integer) annot.attributes().get(Annotation.NAMED)).intValue())); case Annotation.LAUNCH: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.APPLICATION),(String) annot.attributes().get(Annotation.PARAMETERS),(String) annot.attributes().get(Annotation.OPERATION),(String) annot.attributes().get(Annotation.DEFAULTDIR))); default: return new PdfAnnotation(writer, defaultRect.getLeft(), defaultRect.getBottom(), defaultRect.getRight(), defaultRect.getTop(), new PdfString(annot.title(), PdfObject.TEXT_UNICODE), new PdfString(annot.content(), PdfObject.TEXT_UNICODE)); } }
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)); } } }
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; }
/** * 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; } }
/** * Returns a PdfObject that can be used as the value of a Collection Item. * @param v value the value that has to be changed into a PdfObject (PdfString, PdfDate or PdfNumber) */ public PdfObject getValue(String v) { switch(fieldType) { case TEXT: return new PdfString(v, PdfObject.TEXT_UNICODE); case DATE: return new PdfDate(PdfDate.decode(v)); case NUMBER: return new PdfNumber(v); } throw new IllegalArgumentException(v + " is not an acceptable value for the field " + get(PdfName.N).toString()); }
/** * Demonstrates some Layer functionality. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Layers.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); // step 3: writer.setViewerPreferences(PdfWriter.PageModeUseOC); document.open(); // step 4: PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); PdfOCProperties p = writer.getOCProperties(); PdfArray order = new PdfArray(); order.add(l1.getRef()); PdfArray group = new PdfArray(); group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE)); group.add(l2.getRef()); group.add(l3.getRef()); order.add(group); PdfDictionary d = new PdfDictionary(); d.put(PdfName.ORDER, order); p.put(PdfName.D, d); // step 5: we close the document document.close(); }
/** * */ protected void init(PdfContentByte pdfContentByte) { this.pdfContentByte = pdfContentByte; if (isTagged) { PdfStructureTreeRoot root = pdfWriter.getStructureTreeRoot(); PdfName pdfNameALL = new PdfName("All"); root.mapRole(pdfNameALL, PdfName.SECT); root.mapRole(PdfName.IMAGE, PdfName.FIGURE); root.mapRole(PdfName.TEXT, PdfName.TEXT); allTag = new PdfStructureElement(root, pdfNameALL); if(pdfWriter.getPDFXConformance() == PdfWriter.PDFA1A) { root.mapRole(new PdfName("Anchor"), PdfName.NONSTRUCT); root.mapRole(PdfName.TEXT, PdfName.SPAN); } else { root.mapRole(new PdfName("Anchor"), PdfName.TEXT); } if (language != null) { allTag.put(PdfName.LANG, new PdfString(language)); } tagStack = new Stack<PdfStructureElement>(); tagStack.push(allTag); } }
protected void startImage(JRPrintImage printImage) { if (isTagged) { PdfStructureElement imageTag = new PdfStructureElement(allTag, PdfName.IMAGE); pdfContentByte.beginMarkedContentSequence(imageTag); if (printImage.getHyperlinkTooltip() != null) { imageTag.put(PdfName.ALT, new PdfString(printImage.getHyperlinkTooltip())); } } }
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); } }
public CreationListener(cfData _author, cfData _title, cfData _subject, cfData _keywords) { if ( _author != null ) author = new PdfString(_author.toString()); if ( _title != null ) title = new PdfString(_title.toString()); if ( _subject != null ) subject = new PdfString(_subject.toString()); if ( _keywords != null ) keywords = new PdfString(_keywords.toString()); }
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); }
/** * Merge metadata from the FOP-generated PDF and a PDF we're merging into it. * Generally metadata in the merge file takes precedence over the FOP metadata, * but the "overrideMetadata" option reverses that behavior. */ private void mergeMetadata(HashMap<String, String>[] infos, PdfWriter pdfWriter, XPathContext context) throws XPathException { boolean override = getAttribBool("overrideMetadata", context, false); HashMap<String, String> toPut = new HashMap(); if (override) { toPut.putAll(infos[1]); toPut.putAll(infos[0]); } else { toPut.putAll(infos[0]); toPut.putAll(infos[1]); } PdfDictionary outInfo = pdfWriter.getInfo(); for (String key : toPut.keySet()) { // Keep iText as the producer if (key.equals("Producer")) continue; // Filter out empty values. String val = toPut.get(key).trim(); if (val.length() == 0) continue; // Add the new metadata outInfo.put(new PdfName(key), new PdfString(val, PdfObject.TEXT_UNICODE)); } }
/** * Demonstrates how to group optional content. * * @param args * no arguments needed */ public static void main(String[] args) { System.out.println("Grouping optional content"); try { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "contentgroups.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); cb.sanityCheck(); PdfOCProperties p = writer.getOCProperties(); PdfArray order = new PdfArray(); order.add(l1.getRef()); PdfArray group = new PdfArray(); group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE)); group.add(l2.getRef()); group.add(l3.getRef()); order.add(group); PdfDictionary d = new PdfDictionary(); d.put(PdfName.ORDER, order); p.put(PdfName.D, d); // step 5 document.close(); } catch (Exception de) { de.printStackTrace(); } }
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfArray array = (PdfArray)operands.get(0); float tj = 0; for (Iterator i = array.listIterator(); i.hasNext(); ) { Object entryObj = i.next(); if (entryObj instanceof PdfString){ processor.displayPdfString((PdfString)entryObj, tj); tj = 0; } else { tj = ((PdfNumber)entryObj).floatValue(); } } }
/** * 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); } }
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfString string = (PdfString) operands.get(0); processor.displayPdfString(string, 0); }
/** * Demonstrates how to group optional content. */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "contentgroups.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); cb.sanityCheck(); PdfOCProperties p = writer.getOCProperties(); PdfArray order = new PdfArray(); order.add(l1.getRef()); PdfArray group = new PdfArray(); group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE)); group.add(l2.getRef()); group.add(l3.getRef()); order.add(group); PdfDictionary d = new PdfDictionary(); d.put(PdfName.ORDER, order); p.put(PdfName.D, d); // step 5 document.close(); }
public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) { try { PdfWriter writer = exporterContext.getPdfWriter(); PdfIndirectObject swfRef; boolean newContext = !existingContexts.containsKey(exporterContext); if (newContext) { // add the Adobe 1.7 extensions catalog dictionary PdfDictionary extensions = new PdfDictionary(); PdfDictionary adobeExtension = new PdfDictionary(); adobeExtension.put(new PdfName("BaseVersion"), PdfWriter.PDF_VERSION_1_7); adobeExtension.put(new PdfName("ExtensionLevel"), new PdfNumber(3)); extensions.put(new PdfName("ADBE"), adobeExtension); writer.getExtraCatalog().put(new PdfName("Extensions"), extensions); // add the swf file byte[] swfData = readSwf(); PdfFileSpecification swfFile = PdfFileSpecification.fileEmbedded(writer, null, "Open Flash Chart", swfData); swfRef = writer.addToBody(swfFile); existingContexts.put(exporterContext, swfRef); } else { swfRef = (PdfIndirectObject) existingContexts.get(exporterContext); } Rectangle rect = new Rectangle(element.getX() + exporterContext.getOffsetX(), exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY(), element.getX() + exporterContext.getOffsetX() + element.getWidth(), exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight()); PdfAnnotation ann = new PdfAnnotation(writer, rect); ann.put(PdfName.SUBTYPE, new PdfName("RichMedia")); PdfDictionary settings = new PdfDictionary(); PdfDictionary activation = new PdfDictionary(); activation.put(new PdfName("Condition"), new PdfName("PV")); settings.put(new PdfName("Activation"), activation); ann.put(new PdfName("RichMediaSettings"), settings); PdfDictionary content = new PdfDictionary(); HashMap<String, PdfIndirectReference> assets = new HashMap<String, PdfIndirectReference>(); assets.put("map.swf", swfRef.getIndirectReference()); PdfDictionary assetsDictionary = PdfNameTree.writeTree(assets, writer); content.put(new PdfName("Assets"), assetsDictionary); PdfArray configurations = new PdfArray(); PdfDictionary configuration = new PdfDictionary(); PdfArray instances = new PdfArray(); PdfDictionary instance = new PdfDictionary(); instance.put(new PdfName("Subtype"), new PdfName("Flash")); PdfDictionary params = new PdfDictionary(); String chartData = (String) element.getParameterValue(PARAMETER_CHART_DATA); String vars = "inline_data=" + chartData; params.put(new PdfName("FlashVars"), new PdfString(vars)); instance.put(new PdfName("Params"), params); instance.put(new PdfName("Asset"), swfRef.getIndirectReference()); PdfIndirectObject instanceRef = writer.addToBody(instance); instances.add(instanceRef.getIndirectReference()); configuration.put(new PdfName("Instances"), instances); PdfIndirectObject configurationRef = writer.addToBody(configuration); configurations.add(configurationRef.getIndirectReference()); content.put(new PdfName("Configurations"), configurations); ann.put(new PdfName("RichMediaContent"), content); writer.addAnnotation(ann); } catch (Exception e) { throw new RuntimeException(e); } }
private String extractInfo(PdfName key) { PdfString value = (PdfString) info.get(key); return value == null ? null : value.toUnicodeString(); }
/** * Demonstrates some Layer functionality. * * @param args * no arguments needed here */ public static void main(String[] args) { System.out.println("layers"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "Layers.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); // step 3: writer.setViewerPreferences(PdfWriter.PageModeUseOC); document.open(); // step 4: PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); PdfOCProperties p = writer.getOCProperties(); PdfArray order = new PdfArray(); order.add(l1.getRef()); PdfArray group = new PdfArray(); group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE)); group.add(l2.getRef()); group.add(l3.getRef()); order.add(group); PdfDictionary d = new PdfDictionary(); d.put(PdfName.ORDER, order); p.put(PdfName.D, d); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfString string = (PdfString)operands.get(0); processor.displayPdfString(string, 0); }
/** * Displays text. * @param string the text to display * @param tj the text adjustment */ public void displayPdfString(PdfString string, float tj){ String unicode = decode(string); float width = getStringWidth(unicode, tj); // this is width in unscaled units - we have to normalize by the Tm scaling Matrix nextTextMatrix = new Matrix(width, 0).multiply(textMatrix); displayText(unicode, nextTextMatrix); textMatrix = nextTextMatrix; }
/** * Decodes a PdfString (which will contain glyph ids encoded in the font's encoding) * based on the active font, and determine the unicode equivalent * @param in the String that needs to be encoded * @return the encoded String * @since 2.1.7 */ private String decode(PdfString in) { byte[] bytes = in.getBytes(); return gs().font.decode(bytes, 0, bytes.length); }
/** * If this dictionary refers to a child that is a document level attachment, * you need to specify the name that was used to attach the document. * @param target the name in the EmbeddedFiles name tree */ public void setEmbeddedFileName(String target) { put(PdfName.N, new PdfString(target, null)); }