That won't work. You are making the image the same size as the page without taking 
into account the margins. If you want both to be the same size:

boolean open = false;
for (int i=0; i<images.size(); i++) 
{
    byte[] imageByte = jpegEncoder.jpegToByte(images.elementAt(i));
    com.lowagie.text.Image image = 
                com.lowagie.text.Image.getInstance(imageByte);

    if (imageFormat(i).equals("A4")) 
    {
        image.scaleToFit(PageSize.A4.width(), PageSize.A4.height());
        document.setPageSize(PageSize.A4);
    }
    else 
    {
        image.scaleToFit(PageSize.A3.width(), PageSize.A3.height());
        document.setPageSize(PageSize.A3);
    }
    if (!open) {
        document.open();
        open = true;
    }
    image.setAbsolutePosition(0, 0);
    document.add(image);
}
document.close(); 

Best Regards,
Paulo Soares

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Giacomo Galletto
> Sent: Wednesday, September 15, 2004 7:55 AM
> To: [EMAIL PROTECTED]
> Subject: [iText-questions] mixed A3/A3 Pdf documents
> 
> Hi,
> I'm using iText to generate Pdf documents from a java 
> program. These documents 
> have only one image per page. The images are stored in jpg 
> files in the HD 
> after they were scanned from an acquisition device. The 
> format of the paper 
> scanner can be A4 (or less) or A3, so I need to generate Pdf 
> documents that 
> have some pages in A4 format and some pages in A3 format, 
> also alternated.
> I have two Vector: one for the path+filename of the image 
> files and one for 
> the format of each image of the files.
> I tried to do like this: 
> 
> com.lowagie.text.Document document = new com.lowagie.text.Document();
> File filePDF = new File(pathAndFilename);
> FileOutputStream fos = new FileOutputStream(filePDF);
> PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
> document.open();
> 
> for (int i=0; i<images.size(); i++) 
> {
>     byte[] imageByte = jpegEncoder.jpegToByte(images.elementAt(i));
>     com.lowagie.text.Image image = 
>                 com.lowagie.text.Image.getInstance(imageByte);
> 
>     if (imageFormat(i).equals("A4")) 
>     {
>         image.scaleToFit(PageSize.A4.width(), PageSize.A4.height());
>         document.setPageSize(PageSize.A4);
>     }
>     else 
>     {
>         image.scaleToFit(PageSize.A3.width(), PageSize.A3.height());
>         document.setPageSize(PageSize.A3);
>     }
>     image.setAlignment(com.lowagie.text.Image.TOP);
>     document.add(image);
> }
> document.close();
> 
> 
> In fact, if I run this, the Pdf file is generated but the 
> page sizes are 
> always fixed to the first page size, although the image sizes 
> are properly 
> scaled to the right format.
> If I try to add a "document.newPage()" after each 
> format-change passage, the 
> dimensions are setted correctly but an empty page is added 
> between the groups 
> of pages in the same format.
> 
> Any ideas?
> Thanks a lot
> 
> Giacomo
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
> Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
> Camcorder. More prizes in the weekly Lunch Hour Challenge.
> Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> 


-------------------------------------------------------
This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
Camcorder. More prizes in the weekly Lunch Hour Challenge.
Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to