PDF streams in Java

Drawer QR Code JIS X 0510 in Java PDF streams

PDF streams
QR Code Generation In Java
Using Barcode creation for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
Decode QR Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Non-embedded versus embedded fonts
USS Code 128 Creation In Java
Using Barcode encoder for Java Control to generate, create Code 128A image in Java applications.
www.OnBarcode.com
Painting PDF 417 In Java
Using Barcode printer for Java Control to generate, create PDF 417 image in Java applications.
www.OnBarcode.com
a font I downloaded from a site with plenty of free fonts. The font isn t installed on my OS, so Adobe Reader doesn t find it, and the words iText in Action are shown in Adobe Sans MM, which is quite different from the font shown in the PDF that has the font embedded. Suppose you have the upper PDF as well as the font file for the Walt Disney Script font. You could use this listing to embed that font after the fact.
Code128 Generator In Java
Using Barcode maker for Java Control to generate, create Code 128 Code Set B image in Java applications.
www.OnBarcode.com
Code 39 Extended Printer In Java
Using Barcode generator for Java Control to generate, create Code 39 image in Java applications.
www.OnBarcode.com
Listing 16.4 EmbedFontPostFacto.java
Encode QR In Java
Using Barcode generator for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
Making Postnet In Java
Using Barcode maker for Java Control to generate, create Postnet image in Java applications.
www.OnBarcode.com
RandomAccessFile raf = new RandomAccessFile(FONT, "r"); Reads font file byte fontfile[] = new byte[(int)raf.length()]; into byte array raf.readFully(fontfile); raf.close(); PdfStream stream = new PdfStream(fontfile); Creates PDF stream.flateCompress(); stream stream.put(PdfName.LENGTH1, new PdfNumber(fontfile.length)); PdfReader reader = new PdfReader(RESULT1); int n = reader.getXrefSize(); PdfObject object; PdfDictionary font; PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT2)); PdfName fontname = new PdfName(FONTNAME); for (int i = 0; i < n; i++) { object = reader.getPdfObject(i); if (object == null || !object.isDictionary()) Finds unembedded continue; font font = (PdfDictionary)object; if (PdfName.FONTDESCRIPTOR.equals( font.get(PdfName.TYPE)) && fontname.equals( font.get(PdfName.FONTNAME))) {
Generating QR-Code In Objective-C
Using Barcode creator for iPad Control to generate, create QR image in iPad applications.
www.OnBarcode.com
Draw QR In VS .NET
Using Barcode encoder for .NET framework Control to generate, create QR Code image in .NET framework applications.
www.OnBarcode.com
Embedding files into a PDF
Universal Product Code Version A Maker In Objective-C
Using Barcode creator for iPad Control to generate, create UPC Symbol image in iPad applications.
www.OnBarcode.com
Code-128 Generation In None
Using Barcode printer for Font Control to generate, create Code 128 image in Font applications.
www.OnBarcode.com
PdfIndirectObject objref = stamper.getWriter().addToBody(stream); font.put(PdfName.FONTFILE2, objref.getIndirectReference()); } } stamper.close();
Generating Universal Product Code Version A In .NET
Using Barcode drawer for ASP.NET Control to generate, create UPC-A Supplement 2 image in ASP.NET applications.
www.OnBarcode.com
Print Code 128A In .NET
Using Barcode creation for Reporting Service Control to generate, create Code 128 Code Set A image in Reporting Service applications.
www.OnBarcode.com
533 Adds stream to writer Adds reference to stream
UPC - 13 Maker In Visual Studio .NET
Using Barcode drawer for Reporting Service Control to generate, create EAN-13 image in Reporting Service applications.
www.OnBarcode.com
Create European Article Number 13 In None
Using Barcode maker for Microsoft Word Control to generate, create UPC - 13 image in Word applications.
www.OnBarcode.com
In this listing, you re adding the complete font file. You add the reference to the stream using the FONTFILE2 key because you know in advance that the font has TrueType outlines. That s not the only assumption you make. You also assume that the metrics of the font that is used in the PDF correspond to the metrics of the new font you re embedding. When we talked about parsing PDFs, I explained that we could only make a fair attempt, but that the functionality could fail for PDFs using exotic encodings. Several warnings that were mentioned in section 15.3.1 also apply here. In real-world examples, replacing one font with another can be very difficult. Now that you know what a PDF looks like on the inside, these examples complement your knowledge about images (discussed in chapter 10) and fonts (chapter 11). In the sections that follow, we ll take a close look at annotations (chapter 7) that are associated with a PDF stream.
UPC Code Creator In VB.NET
Using Barcode generation for .NET framework Control to generate, create GS1 - 12 image in Visual Studio .NET applications.
www.OnBarcode.com
Making Linear 1D Barcode In Visual Basic .NET
Using Barcode generation for .NET Control to generate, create 1D image in .NET applications.
www.OnBarcode.com
16.2 Embedding files into a PDF
Code 128 Code Set B Decoder In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Printing Barcode In None
Using Barcode maker for Online Control to generate, create Barcode image in Online applications.
www.OnBarcode.com
You ve already created a document with file attachment annotations in section 7.3.3. You can embed different files of any type images, Word documents, XML files, other PDF files into a PDF document as an annotation, but there s also an alternative way to do this. In this section, we ll briefly return to file attachment annotations, and you ll learn about document-level attachments and create actions to open these annotations. We ll also discuss the concept of portable collections.
16.2.1 File attachment annotations
Figure 16.2 shows a list of Kubrick movies available in video stores. There s a pushpin next to every movie title, and if you click the pushpin, the movie poster is shown. All the file attachments are also listed in the file attachments panel at the bottom. The next listing demonstrates how you can extract the attached files by looping over all the pages of the document, inspecting the /Annots array.
PDF streams
File attachment annotations
Listing 16.5 KubrickDvds.java
PdfReader reader = new PdfReader(src); PdfArray array; PdfDictionary annot; PdfDictionary fs; Loops over PdfDictionary refs; pages for (int i = 1; i <= reader.getNumberOfPages(); i++) { array = reader.getPageN(i).getAsArray(PdfName.ANNOTS); Gets if (array == null) continue; annotations for (int j = 0; j < array.size(); j++) { annot = array.getAsDict(j); Looks for file if (PdfName.FILEATTACHMENT attachments .equals(annot.getAsName(PdfName.SUBTYPE))) { fs = annot.getAsDict(PdfName.FS); Gets file specification refs = fs.getAsDict(PdfName.EF); Reads streams for (PdfName name : refs.getKeys()) { into files FileOutputStream fos = new FileOutputStream( String.format(PATH, Gets embedded fs.getAsString(name).toString())); files fos.write(PdfReader.getStreamBytes( (PRStream)refs.getAsStream(name))); fos.flush();
Embedding files into a PDF
fos.close(); } } } }
Gets embedded files
If you don t want to add an attachment using a visible annotation, you can attach files at the document level.
Copyright © OnBarcode.com . All rights reserved.