hi
i am prasad
pemmisetti , Software Consultant in Zensar Technologies
,India..
i need some help how
to create the one pdf file to another pdf file...
i want to add some
options for existing pdf file
please explain
me
i tried for
your example its creating the 1/4 th page , but i need to A4 size
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class PdfSample3 {
public static void main(String[] args) {
public class PdfSample3 {
public static void main(String[] args) {
System.out.println("Chapter 13 example pdfreader: reading an existing PDF
file");
try
{
// we create a reader for a certain document
PdfReader reader = new PdfReader("D:/backup/UML/JDK14_tutorial.pdf");
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
// we retrieve the size of the first page
Rectangle psize = reader.getPageSize(1);
float width = psize.width();
float height = psize.height();
// step 1: creation of a document-object
// we create a reader for a certain document
PdfReader reader = new PdfReader("D:/backup/UML/JDK14_tutorial.pdf");
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
// we retrieve the size of the first page
Rectangle psize = reader.getPageSize(1);
float width = psize.width();
float height = psize.height();
// step 1: creation of a document-object
// Document
document = new Document(psize, 50, 50, 50,
50);
Document document =new Document(PageSize.A4.rotate());
// step 2: we create a writer that listens to the document
Document document =new Document(PageSize.A4.rotate());
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("jdk1.4.11.pdf"));
//
step 3: we open the document
/* try
{
Watermark watermark = new Watermark(Image.getInstance("C:/Documents and
Settings/bj21812/My Documents/My Pictures/annu.bmp"), 200, 320);
document.add(watermark);
}
catch(Exception e) {
System.err.println("Are you sure you have the file 'watermark.jpg' in the right
path?");
}
*/
document.open();
*/
document.open();
//
step 4: we add
content
PdfContentByte cb = writer.getDirectContent();
PdfContentByte cb = writer.getDirectContent();
int i
= 0;
int p
= 0;
System.out.println("There are " + n + " pages in the document.");
while
(i < n) {
document.newPage();
p++;
i++;
PdfImportedPage page1 = writer.getImportedPage(reader, i);
cb.addTemplate(page1, .5f, 0, 0, .5f, 0, width /
2);
System.err.println("processed page " + i);
System.err.println("processed page " + i);
if (i < n) {
i++;
PdfImportedPage page2 = writer.getImportedPage(reader, i);
cb.addTemplate(page2, .5f, 0, 0, .5f, width / 2, height / 2);
System.err.println("processed page " + i);
}
if (i < n) {
i++;
PdfImportedPage page3 = writer.getImportedPage(reader, i);
cb.addTemplate(page3, .5f, 0, 0, .5f, 0, 0);
System.err.println("processed page " + i);
}
if (i < n) {
i++;
PdfImportedPage page4 = writer.getImportedPage(reader, i);
cb.addTemplate(page4, .5f, 0, 0, .5f, width / 2, 0);
System.err.println("processed page " + i);
}*/
/*cb.setRGBColorStroke(255, 0, 0);
cb.moveTo(0, height / 2);
cb.lineTo(width, height / 2);
cb.stroke();
cb.moveTo(width / 2, height);
cb.lineTo(width / 2, 0);
cb.stroke();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 14);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "page " + p + " of " + ((n / 4)
+ (n % 4 > 0? 1 : 0)), width / 2, 40, 0);
cb.endText();
}
//
step 5: we close the document
document.close();
}
catch
(Exception de) {
de.printStackTrace();
}
}
}
Thanks &
regards
prasad
pemmisetti
This email may contain confidential or privileged information for the intended recipient(s) and the views expressed in the same are not necessarily the views of Zensar Technologies Ltd. If you are not the intended recipient or have received this e-mail by error, its use is strictly prohibited, please delete the e-mail and notify the sender. Zensar Technologies Ltd. does not accept any liability for virus infected mails.
