Thanks for clearing that up. Seems I might be closer. The cleaned up code is
below

public class FormPdfView extends AbstractPdfView {

        protected void buildPdfDocument(Map model, Document document, PdfWriter
writer, HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, 
IOException {
                
                PdfFormModel pdfFormModel = (PdfFormModel) 
model.get("pdfFormModel");
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                String readPdf =
"C:\\TRMWorkspace\\ClearView\\WebContent\\WEB-INF\\resources\\forms\\CAI0708.pdf";
                String result =
"C:\\TRMWorkspace\\ClearView\\WebContent\\WEB-INF\\resources\\forms\\ENABLED_CAI.07.10.08.pdf";
                
                try {
                        // Step A document stamping
                        PdfReader reader = new PdfReader(readPdf);
                        
                        System.out.println("Pdf Version: 
"+reader.getPdfVersion());
                        System.out.println("Num of Pages: "+ 
reader.getNumberOfPages());
                        System.out.println("File Length: 
"+reader.getFileLength());
                        System.out.println("Encrypted: "+reader.isEncrypted());
                        
                        // Step B document stamping
                        PdfStamper stamper = new PdfStamper(reader, bos);

                        // Step C document stamping
                        AcroFields form = stamper.getAcroFields();
                        form.setField("fullName", "Blackie Lawless");
                        form.setField("representativeName", "Rob Halford");
                        
                        // Step D document stamping
                        stamper.close();
                        
                        response.setContentType("application/pdf");
                        response.setContentLength(bos.size());
                        response.setHeader("Expires", "0");
                        response.setHeader("Cache-Control", "must-revalidate, 
post-check=0,
pre-check=0");
                        response.setHeader("Pragma", "public");
                        ServletOutputStream out = response.getOutputStream();
                        bos.writeTo(out);
                        out.flush();

                } catch (DocumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
}

On IE6 I get garbage displayed on the screen, FF3 the pdf is returned
(Yay!). But still getting the The document has no pages error. What special
needs to be done for pdf to display with IE6? What could be causing the
error?

Thanks for help!






1T3XT info wrote:
> 
> wmhfitz wrote:
>> Here's my class...
>> 
>> public class FillEnabledForm {
>>  
>>      public static final String ENABLED_FORM = "CAI_0708.pdf";
>>      public static final String RESULT = "ENABLED_CAI.07.10.08.pdf";
>>      static String readPdf =
>> "C:\\TRMWorkspace\\ClearView\\WebContent\\WEB-INF\\resources\\forms\\CAI0708.pdf";
>>  
>>      public static void main(String[] args) {
>>              
>>              Document document = new Document();
>>              ByteArrayOutputStream bos = new ByteArrayOutputStream();
>>              
>>              try {
> 
> This is step A in the document stamping process:
>>                      PdfReader reader = new PdfReader(readPdf);
>>                      System.out.println("Pdf Version: 
>> "+reader.getPdfVersion());
>>                      System.out.println("Num of Pages: "+ 
>> reader.getNumberOfPages());
>>                      System.out.println("File Length: 
>> "+reader.getFileLength());
>>                      System.out.println("Encrypted: "+reader.isEncrypted());
> 
> Why do you need the following line? Are you going to create a new 
> document from scratch? This is step 1 in the document creation process.
>>                      document = new Document();
> 
> No, you are going to stamp an existing document. This is step B in the 
> document stamping process:
>>                      PdfStamper stamper = new PdfStamper(reader, bos);
> 
> This is step 2 in the document creation process. It is commented out.
>> //                   PdfWriter writer = PdfWriter.getInstance(document, bos);
> This is step 3 in the document creation process. It's absurd.
>>                      document.open();
> 
> You are manipulating a form. This is step C in the document stamping 
> process:
>>                      AcroFields form = stamper.getAcroFields();
>>                      form.setField("fullName", "Blackie Lawless");
>>                      form.setField("representativeName", "Rob Halford");
> 
> This is step 5 in the document creation process.
>>                      document.close();
> It throws an error because you omitted step 4!!
> 
> This is step D in the document stamping process.
>>                      stamper.close();
>> 
>>                      } catch (IOException e) {
>>                      e.printStackTrace();    
>>              } catch (DocumentException e) {
>>                      // TODO Auto-generated catch block
>>                      e.printStackTrace();
>>              }
>>      }
>> }
> 
> The answer to your question is clear.
> Either you create a document from scratch using steps 1, 2, 3, 4 and 5.
> Or you manipulate an existing document using steps A, B, C and D.
> 
> You mixed both. That doesn't make sense.
> -- 
> This answer is provided by 1T3XT BVBA
> http://www.1t3xt.com/ - http://www.1t3xt.info
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> 
> Buy the iText book: http://www.1t3xt.com/docs/book.php
> 
> 

-- 
View this message in context: 
http://www.nabble.com/The-document-has-no-pages.-tp21080269p21096739.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to