java qr code reader for mobile Working with existing PDFs in Java

Painting QR-Code in Java Working with existing PDFs

Working with existing PDFs
Generate QR-Code In Java
Using Barcode generator for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
QR Reader In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Scaling and tiling a PDF file
GTIN - 12 Creation In Java
Using Barcode printer for Java Control to generate, create Universal Product Code version A image in Java applications.
www.OnBarcode.com
Print Data Matrix 2d Barcode In Java
Using Barcode maker for Java Control to generate, create ECC200 image in Java applications.
www.OnBarcode.com
The opposite of N-up copying a PDF file is when you have one page, and you want to print it on different pages; see figure 6.6. We already looked at this in chapter 5, but now you ll do the exercise again using PdfImportedPage. The next bit of code takes one page from a PDF document and scales it so that the one page is tiled over 16 pages.
Make UPC A In Java
Using Barcode printer for Java Control to generate, create UPC-A Supplement 5 image in Java applications.
www.OnBarcode.com
EAN 128 Creator In Java
Using Barcode maker for Java Control to generate, create EAN 128 image in Java applications.
www.OnBarcode.com
Listing 6.10 TilingHero.java
Code 128 Generation In Java
Using Barcode generation for Java Control to generate, create Code 128 Code Set C image in Java applications.
www.OnBarcode.com
UCC - 14 Creation In Java
Using Barcode encoder for Java Control to generate, create ITF14 image in Java applications.
www.OnBarcode.com
public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); Rectangle pagesize = reader.getPageSizeWithRotation(1); Document document = new Document(pagesize); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); PdfContentByte content = writer.getDirectContent(); PdfImportedPage page = writer.getImportedPage(reader, 1); float x, y; for (int i = 0; i < 16; i++) { x = -pagesize.getWidth() * (i % 4); y = pagesize.getHeight() * (i / 4 - 3); content.addTemplate(page, 4, 0, 0, 4, x, y); document.newPage(); } document.close(); }
QR Code JIS X 0510 Printer In Java
Using Barcode creation for Android Control to generate, create QR Code JIS X 0510 image in Android applications.
www.OnBarcode.com
Painting QR Code ISO/IEC18004 In None
Using Barcode maker for Word Control to generate, create QR image in Word applications.
www.OnBarcode.com
Adding content with PdfStamper
Code 128 Code Set A Maker In None
Using Barcode creator for Software Control to generate, create Code 128B image in Software applications.
www.OnBarcode.com
EAN-13 Drawer In None
Using Barcode drawer for Excel Control to generate, create European Article Number 13 image in Office Excel applications.
www.OnBarcode.com
In this section, we ve been reusing content from existing PDF documents in a new document. You can take digital photocopies of existing pages, scale them up or down, and use them as if they were an image or an XObject. In the next section, we re going to take an existing PDF and add extra content.
GS1 128 Creator In Java
Using Barcode creator for BIRT reports Control to generate, create EAN128 image in BIRT applications.
www.OnBarcode.com
Make GTIN - 13 In VS .NET
Using Barcode printer for ASP.NET Control to generate, create EAN13 image in ASP.NET applications.
www.OnBarcode.com
Adding content with PdfStamper
Barcode Generator In Visual Studio .NET
Using Barcode generation for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
Barcode Drawer In Objective-C
Using Barcode generation for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Up until now, we ve created new documents using the five steps in the iText document-creation process. In this chapter we ll add content to an existing document using PdfStamper. PdfStamper uses a different mechanism, as demonstrated in the manipulateWithStamper() method.
Painting Code 39 In None
Using Barcode printer for Word Control to generate, create Code 3/9 image in Word applications.
www.OnBarcode.com
PDF 417 Generator In .NET
Using Barcode generation for ASP.NET Control to generate, create PDF417 image in ASP.NET applications.
www.OnBarcode.com
Listing 6.11 SelectPages.java
Draw ANSI/AIM Code 39 In Java
Using Barcode creator for BIRT reports Control to generate, create Code 39 Extended image in BIRT reports applications.
www.OnBarcode.com
Barcode Decoder In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
public static void main(String[] args) throws IOException, DocumentException { new MovieTemplates().createPdf(MovieTemplates.RESULT); PdfReader reader = new PdfReader(MovieTemplates.RESULT); reader.selectPages("4-8"); manipulateWithStamper(reader); ... } private static void manipulateWithStamper(PdfReader reader) throws IOException, DocumentException { PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT1)); stamper.close(); }
You ve already seen part of this example in listing 6.3. It s an example that creates a new PDF document containing only a selection of pages from the original document. In B, you create a PdfReader that will read the 8 pages of the timetable PDF, but you immediately tell the reader that you re only interested in pages 4 to 8. In C, you create a PdfStamper object. As soon as you close the stamper, a new document will be created. It will contain only 5 pages. You can add content between the constructor and the close() method.
Adding content at absolute positions Let s start with the Hello World examples with paper size Letter in landscape format from chapter 1. There were two versions of this example. Let s add the words Hello people!
Listing 6.12 StampText.java
PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); PdfContentByte canvas = stamper.getOverContent(1); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Hello people!"), 36, 540, 0); stamper.close();
Working with existing PDFs
Adding text to an existing document
The getOverContent() method is similar to the getDirectContent() method discussed in chapter 3. It returns a PdfContentByte object that allows you to write to a new layer that goes on top of the existing content of the page you choose. There s also a getUnderContent() method, which is the equivalent of getDirectContentUnder().
NOTE
The methods getOverContent() and getUnderContent() give you the option to write to the direct content on a layer that goes on top of or below the existing content. They don t give you access to the layer with the existing content. You can t use these methods to replace existing content, nor to complete it. It s not possible to say: I want to add the words Hello people! after the words Hello World . You can only add those words to the layer above or below the existing content at an absolute position whose coordinates you know.
The media box of the file that was used as the basis for hello3.pdf was 792 pt x 612 pt. I ve added the extra text at the coordinates (36,540). That s near the top-left corner. The file used as the basis for hello1.pdf had a media box measuring 612 pt x 792 pt, but the page had a rotation of 90 degrees. The difference between these two ways of creating a page in landscape is made transparent: iText took the rotation into account and rotated the coordinate system. If you don t want this, you can tell iText to ignore the fact that the page is rotated. That s what happened with hello2.pdf in figure 6.7. In the next code snippet, the extra text was added at the same coordinates as in listing 6.12, but the rotation of the page isn t taken into account. This is prevented with the setRotateContents() method.
Adding content with PdfStamper Listing 6.13 StampText.java (continued)
PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.setRotateContents(false); PdfContentByte canvas = stamper.getOverContent(1); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Hello people!"), 36, 540, 0); stamper.close();
We could now repeat everything that we covered in chapter 3, and explain how to draw lines, shapes, and text to the PdfContentByte layers obtained with getOverContent() and getUnderContent(), but it s a better idea to look at practical examples.
Copyright © OnBarcode.com . All rights reserved.