Hey,
<span style=“font-size:10.0pt;font-family:“Courier New”;
color:blue”>public<span style=“font-size:10.0pt;font-family:“Courier New””>
static Document
InsertDocumentAsImages(Document srcDoc)
{
// Load the blank base template to use
Document dstDoc = new Document();
// Reset page margins
dstDoc.FirstSection.PageSetup.LeftMargin = 0;
dstDoc.FirstSection.PageSetup.RightMargin = 0;
dstDoc.FirstSection.PageSetup.TopMargin = 0;
dstDoc.FirstSection.PageSetup.BottomMargin = 0;
DocumentBuilder builder = new DocumentBuilder(dstDoc);
// Iterate through each page in the source document
for (int page = 0; page < srcDoc.PageCount; page++)
{
// Get the page details of the current page.
PageInfo pageInfo = srcDoc.GetPageInfo(page);
// Find the margins of the current page. If the document has sections with different margins
// some extra logic is required here.
PageSetup ps = dstDoc.FirstSection.PageSetup;
// The total size of the vertical margins in the destination document.
double marginHeight = ps.TopMargin + ps.BottomMargin;
// The space free on the page minus margins.
double freeHeight = ps.PageHeight - marginHeight;
// The scale required to insert the page into the destination document and to have it
// fit within the vertical margins.
float scale = (float)(freeHeight / ps.PageHeight);
// Set the resolution of the image here.
float resolution = 96f;
// Get the transformed size
Size pageSize = pageInfo.GetSizeInPixels(scale, resolution);
// Stores the page rendered to image.
MemoryStream imageStream = new MemoryStream();
using (Bitmap img = new Bitmap(pageSize.Width, pageSize.Height))
{
img.SetResolution(resolution, resolution);
using (Graphics gr = Graphics.FromImage(img))
{
// You can apply various settings to the Graphics object.
gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
// Fill the page background.
gr.FillRectangle(Brushes.White, 0, 0, pageSize.Width, pageSize.Height);
// Render the page using the zoom.
srcDoc.RenderToScale(page, gr, 0, 0, scale);
}
img.Save(imageStream, ImageFormat.Bmp);
}
// Insert the page image into the base document.
builder.InsertImage(imageStream);
}
return dstDoc;
}
Thanks !
garkler