----- Original Message -----
From: "Dharmendra Kumar" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Monday, August 06, 2007 12:37 PM
Subject: Re: [iText-questions] Problem in Importing Landscape PDF Doc.
> Thanks for the reply.
>
> That's not a problem for me because before coming to this snippet the
> previous page has already been populated with some thing else.
>
> The situation here is like this. I have bunch of reports needs to be
> bundeled together for which I have written a frame work using iText and it
> works perfectly fine. Now I have a requirement where the end user will
> upload some PDF files and those files needs to be merged with generated
> PDF.
> So first I tried using PdfCopy but I guess it has some limitations (as for
> as I know). It does not allows me to write some thing of my own in current
> document. Even if I do so that page does not come up in final PDF.
>
The PdfCopy in the SVN allows adding content, annotations and new fields.
> I solve my problem using Image. So I am seeing if the page rotation is not
> zero then re rotate by the same angle in -ve direction. But still I am
> wondering if I have a better solution. Here is the code currently I am
> using
>
That's a good solution.
Paulo
> private boolean insertPDFStaticPage(Document doc, byte[] pdfByte,
> boolean isDemo, boolean isHeaderRequired, PDFMetaDataBuilder
> metadataBuilder){
>
> PdfWriter writer = metadataBuilder.getWriter();
> int tocPos = 0;
> if (pdfByte == null){
> return false;
> }
>
> PDFContent headerContent =
> metadataBuilder.getHeaderContent();
> PdfPTable header = headerContent.getContent();
> Position hPos = headerContent.getPosition();
> try{
>
> PdfReader staticPageReader = new PdfReader(pdfByte);
> PdfContentByte cb = writer.getDirectContent();
> PdfImportedPage staticPages = null;
>
> int noOfPages = staticPageReader.getNumberOfPages();
> for ( ; tocPos< noOfPages; ){
> ++tocPos;
> Rectangle pageRect =
> staticPageReader.getPageSizeWithRotation(tocPos);
> int pageRotation = pageRect.getRotation();
> doc.setPageSize(pageRect);
> doc.newPage();
> staticPages =
> writer.getImportedPage(staticPageReader,tocPos);
> //needs to use Image as using only imported
> page does not gaurantee you for content rotation
> Image pageImage =
> Image.getInstance(staticPages);
> pageImage.setAbsolutePosition(0f,0f);
> if(pageRotation != 0){
>
> pageImage.setRotationDegrees(-pageRotation);
> }
> doc.add(pageImage);
>
> //cb.addTemplate(staticPages,0f,0f);
>
> //write header if required
> if (!isHeaderRequired){
>
> header.writeSelectedRows(hPos.getRowStart(),hPos.getRowEnd(),hPos.getXPos(),
> hPos.getYPos(),cb);
> }
> //check if water mark required
> if (isDemo){
>
> ContentHelper.addWaterMarkTemplate(writer.getDirectContent());
> }
> }
> }catch(Exception e){
> logger.log(e);
> }
> return true;
> }
>
> Dharmendra Kumar
> Extn: 8402
> Be yourself. Everyone else is already taken.
>
>
>> _____________________________________________
>> From: Dharmendra Kumar
>> Sent: Wednesday, August 01, 2007 4:46 PM
>> To: '[EMAIL PROTECTED]'
>> Cc: '[email protected]'
>> Subject: Problem in Importing Landscape PDF Doc.
>>
>> Hi Bruno,
>> I am facing a strange problem. Don't know if I am missing some steps. So
>> the problem is when I import a landscape page and tries to render it in
>> my
>> own PDF it renders the content and everything but the content of the page
>> is -180 degree rotated. I mean the content seems running from bottom to
>> top instead of left to right. Here is the code snippet I am using.
>>
>> Document document = new Document(PageSize.A4);
>> FileOutputStream os = new FileOutputStream("LandScape+Portrait.pdf");
>> PdfWriter writer = PdfWriter.getInstance(document, os);
>> document.open();
>> PdfContentByte cb = writer.getDirectContent();
>> PdfReader reader = new PdfReader("myFile.pdf");
>> PdfImportedPage staticPages = null;
>> int n = reader.getNumberOfPages();
>> for (int j = 0; j < n; ) {
>> ++j;
>> document.setPageSize(reader.getPageSizeWithRotation(j));
>> staticPages = writer.getImportedPage(reader,j);
>>
>> document.newPage();
>> cb.addTemplate(staticPages,0f, 0f);
>> }
>> document.close();
>>
>> Please help.
>>
>> Dharmendra Kumar
>> Extn: 8402
>> There is no 'I' in Team.
-------------------------------------------------------------------------
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/