Hi,

How to save the pdf file into the database? I have a method that display the
pdf into web browser. How to save the generated pdf into database? Here is
my code. 

What shoud be the additional code to persist the pdf in the database?
Thanks.

response.setContentType("application/pdf");
        if (sendAsAttachment) {
            response.setHeader("Content-Disposition", " attachment;
filename=\"sarFormDI.pdf\"");
        }
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();

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);
        
        /*
         * 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));
        writer.addPage(writer.getImportedPage(reader, 3));
        document.close();

-- 
View this message in context: 
http://www.nabble.com/saving-pdf-into-the-database-after-streaming-tf4163240.html#a11845679
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/

Reply via email to