pls help me on this
dreamboy wrote:
>
> I got stuck with this one...I followed your instruction but i dont know
> how to integrate in the last part. This is to be rendered in web page. In
> pages 1 and 2, im successful in storing the pdf in memory but the last
> page which contains overflow String, I cant write the columnText to
> writer. Could you guide how to do it? Below is my code.
>
> // TODO Auto-generated method stub
> /*
> * Set HTTP Content Type
> */
> response.setContentType("application/pdf");
> //response.addHeader("Pragma", "public");
> //response.addHeader("Cache-Control", "max-age=0");
>
> //response.setHeader("Content-Disposition", " attachment;
> filename=\"sarFormDI.pdf\"");
> /*
> * If User clicked on the Save button, force the browser to open a
> Save As dialog.
> */
> if (sendAsAttachment) {
> response.setHeader("Content-Disposition", " attachment;
> filename=\"sarFormDI.pdf\"");
> }
> /*
> * First, stamp the form while keeping the result in memory
> * (as there could be multiple associated subjects and we need
> * to generate page 1 for each one).
> */
> PdfReader reader = new
> PdfReader(context.getResourceAsStream(OLD_SAR_FORM_FILE));
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> PdfStamper stamper = new PdfStamper(reader, baos);
>
> /*
> * Property file is used to abstract away generic form field names
> */
> Properties props =
> getSARFormProperties(context.getResourceAsStream(SAR_FORM_FIELDS_MAPPING_FILE));
> /*
> * Get Acroform fields
> */
> AcroFields form = stamper.getAcroFields();
>
>
>
> /*
> * Part I - Subject Information
> */
> Iterator<SarSubjectDTO> assocSubjects = null;
> if (formData.getSubjects() != null &&
> formData.getSubjects().size() > 0) {
> assocSubjects = formData.getSubjects().iterator();
> SarSubjectDTO subject = assocSubjects.next();
> fillSubjectInfoSection(props, form, subject);
>
> }
> else{
>
> form.setField(props.getProperty(SUBJECT_INFO_UNAVAILABLE),"Yes");
> }
> fillSuspiciousActivityInfo(props, form, formData);
> fillupFieldList(formData,props, form);
> fillReportingFinancialInfo(formData, props, form);
> fillActivityLocation(formData, props, form);
> fillAccountInfo(formData, props, form);
> fillLawEnforcementAgency(props, form, formData);
> fillNarrative(props, form, formData);
> fillContactForAssistance(props, form, formData);
>
> float[] narrativeFieldPositions =
> form.getFieldPositions(props.getProperty(NARRATIVE));
> float lx = narrativeFieldPositions[1];
> float ly = narrativeFieldPositions[2];
> float rx = narrativeFieldPositions[3];
> float ry = narrativeFieldPositions[4];
>
> /*
> * Flattening the form removed input fields so that the form is
> * no longer editable.
> */
> stamper.setFormFlattening(true);
> stamper.close();
> /*
> * Now read the stamped and flattened file from memory and copy
> Page 1.
> */
> reader = new PdfReader(baos.toByteArray());
> Document document = new
> Document(reader.getPageSizeWithRotation(1));
> PdfCopy writer = new PdfCopy(document,
> response.getOutputStream());
> document.open();
> writer.addPage(writer.getImportedPage(reader, 1));
> if (assocSubjects != null) {
> /*
> * Iterate over remaining associated subjects: for each one
> create a separate
> * form in memory and copy Page 1 to the original final
> document.
> */
> while (assocSubjects.hasNext()) {
> SarSubjectDTO subject = assocSubjects.next();
> PdfReader reader2 = new
> PdfReader(context.getResourceAsStream(OLD_SAR_FORM_FILE));
> baos = new ByteArrayOutputStream();
> stamper = new PdfStamper(reader2, baos);
> form = stamper.getAcroFields();
> fillSubjectInfoSection(props, form, subject);
> stamper.setFormFlattening(true);
> stamper.close();
> reader2 = new PdfReader(baos.toByteArray());
> writer.addPage(writer.getImportedPage(reader2, 1));
> }
> }
> /*
> * Finally, copy over the remaining pages
> */
>
>
> writer.addPage(writer.getImportedPage(reader, 2));
> PdfReader reader3 = new PdfReader(baos.toByteArray());
> ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
> PdfStamper stamper2 = new PdfStamper(reader3, baos2);
> PdfImportedPage narrativePage =
> stamper2.getImportedPage(reader3,3);
>
> int pageCt = reader3.getNumberOfPages();
> System.out.println("pageCt "+pageCt);
> //PdfContentByte cb = stamper2.getOverContent(pageCt);
> PdfContentByte cb = writer.getDirectContent();
> ColumnText ct = new ColumnText(cb);
> ct.setSimpleColumn(lx,ly,rx,ry);
> ct.setText(new Phrase(formData.getNarrative()));
> int status = ct.go();
>
> while ( ColumnText.hasMoreText(status) ) {
> stamper2.insertPage(++pageCt, PageSize.LETTER);
> cb = stamper2.getOverContent(pageCt);
> cb.addTemplate(narrativePage,0,0); // add the static page as
> background
> ct.setCanvas(cb);
> ct.setYLine(ry);
> status = ct.go();
>
> }
>
> // BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
> BaseFont.WINANSI,
> // BaseFont.NOT_EMBEDDED);
> // for (int pageNo = 1; pageNo <= pageCt; pageNo++) {
> // cb = stamper2.getOverContent(pageNo);
> // cb.beginText();
> // cb.setFontAndSize(bf, 12);
> // cb.setTextMatrix(522, 10);
> // cb.showText("Page " + pageNo + " of " + pageCt);
> // cb.endText();
> // }
> //
>
>
>
> writer.addPage(writer.getImportedPage(reader, 3));
>
>
> document.close();
>
>
>
>
>
>
>
>
>
>
>
>
>
> Bruno Lowagie (iText) wrote:
>>
>> dreamboy wrote:
>>> is there a way to count the line of this field so that, I can fix the
>>> number
>>> of lines to be displayed?
>>> what is another approach? I want the font size to be fixed
>>
>> See the mailing list archives.
>> Look for 'BINGO' in Subject: and for Paul Gatewood in From:
>> Here's an URL to the solution:
>> http://www.nabble.com/Re%3A-BINGO%21-creating-new-document-where-every-page-includes-contents-%28text-and-form-fields%29-from-pdf-template-file-p8502943.html
>> br,
>> Bruno
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Splunk Inc.
>> Still grepping through log files to find problems? Stop.
>> Now Search log events and configuration files using AJAX and a browser.
>> Download your FREE copy of Splunk now >> http://get.splunk.com/
>> _______________________________________________
>> iText-questions mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/set-the-proper-font-size-tf4197106.html#a11959878
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/