Hello everyone.

I use the iTextSharp to split in pages one pdf file. In some cases the pages on the original document contains certain information not available in the pdf for the same page generated by the
library.
The following is the code I actually use.

protected bool SplitPDFFile_ExtractOnePage(string SourcefilePath, string DestinyPagePath, int PageNumber)
{
bool aResult = false;
try
{

// get input document
PdfReader inputPdf = new PdfReader(SourcefilePath);


// load the input document
Document inputDoc =
new Document(inputPdf.GetPageSizeWithRotation(1));

// create the filestream
FileStream fs = new FileStream(DestinyPagePath, FileMode.Create);

// create the output writer
PdfWriter outputWriter = PdfWriter.GetInstance(inputDoc, fs);
inputDoc.Open();
PdfContentByte cb1 = outputWriter.DirectContent;


// copy pages from input to output document
inputDoc.SetPageSize(inputPdf.GetPageSizeWithRotation(PageNumber));
inputDoc.NewPage();


PdfImportedPage page =
outputWriter.GetImportedPage(inputPdf, PageNumber);
int rotation = inputPdf.GetPageRotation(PageNumber);


if (rotation == 90 || rotation == 270)
{
cb1.AddTemplate(page, 0, -1f, 1f, 0, 0,
inputPdf.GetPageSizeWithRotation(PageNumber).Height);
}
else
{
cb1.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}

inputDoc.Close();

aResult = true;
}
catch { }

aResult = aResult && File.Exists(DestinyPagePath);

return aResult;
}

Thanks in advance for any help
Enediel
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to