com.lowagie.text.pdf.PdfObject Java Examples
The following examples show how to use
com.lowagie.text.pdf.PdfObject.
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: 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 #2
Source File: PdfContentStreamProcessor.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
public static byte[] getContentBytesFromPdfObject(PdfObject object) throws IOException { switch (object.type()) { case PdfObject.INDIRECT: return getContentBytesFromPdfObject(PdfReader.getPdfObject(object)); case PdfObject.STREAM: return PdfReader.getStreamBytes((PRStream) PdfReader.getPdfObject(object)); case PdfObject.ARRAY: ByteArrayOutputStream baos = new ByteArrayOutputStream(); ListIterator<PdfObject> iter = ((PdfArray) object).listIterator(); while (iter.hasNext()) { PdfObject element = iter.next(); baos.write(getContentBytesFromPdfObject(element)); } return baos.toByteArray(); default: throw new IllegalStateException("Unsupported type: " + object.getClass().getCanonicalName()); } }
Example #3
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 #4
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 #5
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 #6
Source File: ITextPDFSignatureService.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
private PdfObject generateFileId(PAdESCommonParameters parameters) { try (ByteBuffer buf = new ByteBuffer(90)) { String deterministicId = DSSUtils.getDeterministicId(parameters.getSigningDate(), null); byte[] id = deterministicId.getBytes(); buf.append('[').append('<'); for (int k = 0; k < 16; ++k) { buf.appendHex(id[k]); } buf.append('>').append('<'); for (int k = 0; k < 16; ++k) { buf.appendHex(id[k]); } buf.append('>').append(']'); return new PdfLiteral(buf.toByteArray()); } catch (IOException e) { throw new DSSException("Unable to generate the fileId", e); } }
Example #7
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 #8
Source File: PdfCollectionSort.java From itext2 with GNU Lesser General Public License v3.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 #9
Source File: PdfCollectionField.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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()); }
Example #10
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 #11
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 #12
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 #13
Source File: ITextPdfArray.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public long getObjectNumber(int i) { PdfObject pdfObject = wrapped.getPdfObject(i); if (pdfObject.isStream()) { PdfStream asStream = wrapped.getAsStream(i); return asStream.getIndRef().getNumber(); } else if (pdfObject.isIndirect()) { PdfIndirectReference asIndirectObject = wrapped.getAsIndirectObject(i); return asIndirectObject.getNumber(); } throw new DSSException("Not supported " + pdfObject); }
Example #14
Source File: PdfAnnotationsImp.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
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)); } }
Example #15
Source File: PdfContentStreamProcessorTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
private byte[] readContentBytes(final PdfObject contentObject) throws IOException { final byte[] result; switch (contentObject.type()) { case PdfObject.INDIRECT: final PRIndirectReference ref = (PRIndirectReference) contentObject; final PdfObject directObject = PdfReader.getPdfObject(ref); result = readContentBytes(directObject); break; case PdfObject.STREAM: final PRStream stream = (PRStream) PdfReader.getPdfObject(contentObject); result = PdfReader.getStreamBytes(stream); break; case PdfObject.ARRAY: // Stitch together all content before calling processContent(), // because // processContent() resets state. final ByteArrayOutputStream allBytes = new ByteArrayOutputStream(); final PdfArray contentArray = (PdfArray) contentObject; final ListIterator<?> iter = contentArray.listIterator(); while (iter.hasNext()) { final PdfObject element = (PdfObject) iter.next(); allBytes.write(readContentBytes(element)); } result = allBytes.toByteArray(); break; default: final String msg = "Unable to handle Content of type " + contentObject.getClass(); throw new IllegalStateException(msg); } return result; }
Example #16
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 #17
Source File: PdfCollectionSort.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Defines the sort order of the field (ascending or descending). * @param ascending true is the default, use false for descending order */ public void setSortOrder(boolean ascending) { PdfObject o = get(PdfName.S); if (o instanceof PdfName) { put(PdfName.A, new PdfBoolean(ascending)); } else { throw new IllegalArgumentException("You have to define a boolean array for this collection sort dictionary."); } }
Example #18
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 #19
Source File: Image.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets a PDF Name from an array or returns the object that was passed. */ private PdfObject simplifyColorspace(PdfArray obj) { if (obj == null) return obj; PdfName first = obj.getAsName(0); if (PdfName.CALGRAY.equals(first)) return PdfName.DEVICEGRAY; else if (PdfName.CALRGB.equals(first)) return PdfName.DEVICERGB; else return obj; }
Example #20
Source File: PdfCollectionSort.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Defines the sort order of the field (ascending or descending). * @param ascending true is the default, use false for descending order */ public void setSortOrder(boolean ascending) { PdfObject o = get(PdfName.S); if (o instanceof PdfName) { put(PdfName.A, new PdfBoolean(ascending)); } else { throw new IllegalArgumentException("You have to define a boolean array for this collection sort dictionary."); } }
Example #21
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 #22
Source File: ITextPDFSignatureService.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
private PdfObject getPdfObjectForToken(Token token, Map<String, Long> knownObjects, PdfReader reader, PdfWriter writer) throws IOException { String digest = getTokenDigest(token); Long objectNumber = knownObjects.get(digest); if (objectNumber == null) { PdfStream ps = new PdfStream(token.getEncoded()); return writer.addToBody(ps, false).getIndirectReference(); } else { return new PRIndirectReference(reader, objectNumber.intValue()); } }
Example #23
Source File: PdfCollectionField.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * 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()); }
Example #24
Source File: PdfCollectionField.java From gcs with 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 #25
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 #26
Source File: ITextPdfDict.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Date getDateValue(String name) { PdfObject pdfObject = wrapped.get(new PdfName(name)); PdfString s = (PdfString) pdfObject; if (s == null) { return null; } return PdfDate.decode(s.toString()).getTime(); }
Example #27
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 #28
Source File: PdfAnnotationsImp.java From gcs with Mozilla Public License 2.0 | 5 votes |
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)); } }
Example #29
Source File: Image.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Gets a PDF Name from an array or returns the object that was passed. */ private PdfObject simplifyColorspace(PdfArray obj) { if (obj == null) { return obj; } PdfName first = obj.getAsName(0); if (PdfName.CALGRAY.equals(first)) { return PdfName.DEVICEGRAY; } else if (PdfName.CALRGB.equals(first)) { return PdfName.DEVICERGB; } else { return obj; } }
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); }