Steve Wells wrote:
> Hi,
>  
> Thank you very much for your follow-up to prior inquiry & the PDF attachment 
> you then included appears exactly as we'd like; however I didn't find any 
> corresponding source to confirm + compare our logic against.

That's because you're supposed to buy and read the book so that the 
author gets some financial rewards for his work. (He has to earn a 
living too.)

> Would you please help identify + include the exact procedure your code used 
> to achieve what you prepared & sent?

OK, just for this once, I'll show the method I wrote to generate the PDF 
that was sent in attachment in a previous mail.

public static void createPdf() throws IOException, DocumentException {
   Document document = new Document();
   PdfWriter writer = PdfWriter.getInstance(
     document, new FileOutputStream("ballots.pdf"));
   writer.setViewerPreferences(PdfWriter.PageModeUseThumbs);
   PdfPageLabels pageLabels = new PdfPageLabels();
   int dpiX, dpiY;
   float imgWidthPica, imgHeightPica;
   TreeSet<File> images = new TreeSet<File>();
   for (int i = 0; i < FILES.length; i++) {
     images.add(new File(FILES[i]));
   }
   String label;
   for (File image: images) {
     try {
       Image img = Image.getInstance(image.getAbsolutePath());
       dpiX = img.getDpiX();
       if (dpiX == 0) {
         dpiX = 72;
       }
       dpiY = img.getDpiY();
       if (dpiY == 0) {
         dpiY = 72;
       }
       imgWidthPica = (72 * img.getPlainWidth()) / dpiX;
       imgHeightPica = (72 * img.getPlainHeight()) / dpiY;
       img.scaleAbsolute(imgWidthPica, imgHeightPica);
       document.setPageSize(new Rectangle(imgWidthPica, imgHeightPica));
       if (document.isOpen()) {
         document.newPage();
       }
       else {
         document.open();
       }
       img.setAbsolutePosition(0, 0);
       document.add(img);
       label = image.getName();
       if (label.lastIndexOf('.') > 0) {
         label = label.substring(0, label.lastIndexOf('.'));
       }
       pageLabels.addPageLabel(
         writer.getPageNumber(), PdfPageLabels.EMPTY, label);
       }
       catch (Exception e) {
         System.err.println(e.getMessage());
       }
     }
     if (document.isOpen()) {
       writer.setPageLabels(pageLabels);
       document.close();
     }
}

If you don't like the opened Thumbnails panel, you can remove the line 
that sets the viewer preferences. The same goes for the page labels. 
This code shows the file name as a page label; maybe that's overkill in 
your application.
-- 
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to