int f = 1;
PdfReader reader = new PdfReader("Chap0101.pdf");
int n = reader.NumberOfPages;
Document documentUnit = new Document(reader.GetPageSizeWithRotation(1));
PdfWriter writer = PdfWriter.GetInstance(documentUnit, new FileStream("Chap0103.pdf", FileMode.Create));
documentUnit.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
int rotation;
while (f < 3)
{
int i = 0;
while (i < n)
{
i++;
documentUnit.SetPageSize(reader.GetPageSizeWithRotation(i));
documentUnit.NewPage();
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
f++;
if (f < 3)
{
reader = new PdfReader("Chap0102.pdf");
n = reader.NumberOfPages;
}
}
documentUnit.Close();
PdfReader reader = new PdfReader("Chap0101.pdf");
int n = reader.NumberOfPages;
Document documentUnit = new Document(reader.GetPageSizeWithRotation(1));
PdfWriter writer = PdfWriter.GetInstance(documentUnit, new FileStream("Chap0103.pdf", FileMode.Create));
documentUnit.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
int rotation;
while (f < 3)
{
int i = 0;
while (i < n)
{
i++;
documentUnit.SetPageSize(reader.GetPageSizeWithRotation(i));
documentUnit.NewPage();
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
f++;
if (f < 3)
{
reader = new PdfReader("Chap0102.pdf");
n = reader.NumberOfPages;
}
}
documentUnit.Close();
No comments:
Post a Comment