Hi All-
I have problem while editing existing PDF file that the text that I have
added in existing PDF file is not getting visible but search-able. This
existing PDF file is also getting generated from iText. I am using
"itext-1.5.2.jar".
Please find below my code snippet. Please note I am not getting any
exception/errors. My only problem is that the text that I am adding is not
visible even after using color/font etc. I have tried same code to generate
new PDF file to add text; it works fine and text is visible too.
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod(PDFurl);
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
OutputStream newPDF = new FileOutputStream("New.pdf");
PdfReader reader = new
PdfReader(getMethod.getResponseBodyAsStream());
PdfStamper stamper = new PdfStamper(reader, newPDF);
Document document = new
Document(reader.getPageSizeWithRotation(13));
PdfWriter writer = PdfWriter.getInstance(document, newPDF);
float height = writer.getPageSize().height();
float width = writer.getPageSize().width();
document.open();
BaseFont font =
BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.WINANSI,
BaseFont.NOT_EMBEDDED);
PdfContentByte cb1 = writer.getDirectContent();
for (int i = 1; i < reader.getNumberOfPages() + 1; i++)
{
document.newPage();
if(i ==13)
{
drawRectangle(cb1, PageSize.A4.width(),
PageSize.A4.height());
Paragraph p = new Paragraph("Foobar Film Festival",
new
Font(font, 22));
p.setAlignment(Element.ALIGN_CENTER);
document.add(p);
cb1.beginText();
cb1.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
cb1.setFontAndSize(font, 12);
cb1.moveText(400, 663);
cb1.setColorFill(Color.BLACK);
cb1.setRGBColorStroke(0xFF, 0x00, 0x00);
cb1.setRGBColorFill(0xFF, 0xFF, 0xFF);
cb1.showText("CURRENT DATE"); // THIS TEXT
IS
NOT GETTING VISIBLE
cb1.endText();
}
PdfImportedPage page = writer.getImportedPage(reader,
i);
cb1.addTemplate(page, 0, 0);
}
document.close();
writer.close();
reader.close();
newPDF.close();
} else {
System.out.println("Error:");
}
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.ERROR,"Error occurs in the PDFServletTest",e);
}
}
public static void drawRectangle(PdfContentByte content, float width,
float height) {
content.saveState();
PdfGState state = new PdfGState();
state.setFillOpacity(0.6f);
content.setGState(state);
content.setRGBColorFill(0xFF, 0xFF, 0xFF);
content.setLineWidth(3);
content.rectangle(60, 70, width, height);
content.fillStroke();
content.restoreState(); } }
Please respond to me at your earliest. Thanks allot for your help in
advance.
Vikas
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/Editing-existing-PDF-file-Newly-added-text-not-visible-tp3462037p3462037.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php