|
Importing page using PdfTemplate:
//Create new PDF document.
PdfDocument document = new PdfDocument();
//Set marging all 0.
document.PageSettings.Margins.All = 0;
//Loads the input PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("DOC_backup.pdf");
for (int i = 0; i <= loadedDocument.Pages.Count - 1; i++)
{
PdfPage page = document.Pages.Add();
PdfGraphics g = page.Graphics;
//Create PdfTeamplage of existing page.
PdfTemplate template = loadedDocument.Pages[i].CreateTemplate();
//Get the rotation of the page.
PdfPageRotateAngle angle = loadedDocument.Pages[i].Rotation;
g.Save();
//Rotate the page graphics
g.RotateTransform(GetRotationAngle(angle));
g.TranslateTransform(0, -page.GetClientSize().Width);
//Draw PdfTemplate in PdfPage.
g.DrawPdfTemplate(template, new PointF(0, 0), new SizeF(page.GetClientSize().Height, page.GetClientSize().Width));
g.Restore();
}
//Save the document.
document.Save("output.pdf");
document.Close(true);
GetRotationAngle:
private float GetRotationAngle(PdfPageRotateAngle angle)
{
float m_angle = 0;
switch (angle)
{
case PdfPageRotateAngle.RotateAngle90:
m_angle = 90;
break;
case PdfPageRotateAngle.RotateAngle180:
m_angle = 180;
break;
case PdfPageRotateAngle.RotateAngle270:
m_angle = 270;
break;
}
return m_angle;
}
|
|
PdfLoadedDocument ldoc = new PdfLoadedDocument("270.pdf");
Bitmap map = ldoc.ExportAsImage(0);
PdfBitmap pdfBitmap = new PdfBitmap(map);
|