本文整理汇总了C#中Aspose.Words.Document.RenderToScale方法的典型用法代码示例。如果您正苦于以下问题:C# Document.RenderToScale方法的具体用法?C# Document.RenderToScale怎么用?C# Document.RenderToScale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aspose.Words.Document
的用法示例。
在下文中一共展示了Document.RenderToScale方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createThumbnails
public void createThumbnails()
{
//ExStart
//ExFor:Document.RenderToScale
//ExSummary:Renders individual pages to graphics to create one image with thumbnails of all pages.
// The user opens or builds a document.
Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Rendering.doc");
// This defines the number of columns to display the thumbnails in.
const int thumbColumns = 2;
// Calculate the required number of rows for thumbnails.
// We can now get the number of pages in the document.
int remainder;
int thumbRows = Math.DivRem(doc.PageCount, thumbColumns, out remainder);
if (remainder > 0)
thumbRows++;
// Lets say I want thumbnails to be of this zoom.
const float scale = 0.25f;
// For simplicity lets pretend all pages in the document are of the same size,
// so we can use the size of the first page to calculate the size of the thumbnail.
Size thumbSize = doc.GetPageInfo(0).GetSizeInPixels(scale, 96);
// Calculate the size of the image that will contain all the thumbnails.
int imgWidth = thumbSize.Width * thumbColumns;
int imgHeight = thumbSize.Height * thumbRows;
using (Bitmap img = new Bitmap(imgWidth, imgHeight))
{
// The user has to provides a Graphics object to draw on.
// The Graphics object can be created from a bitmap, from a metafile, printer or window.
using (Graphics gr = Graphics.FromImage(img))
{
gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
// Fill the "paper" with white, otherwise it will be transparent.
gr.FillRectangle(new SolidBrush(Color.White), 0, 0, imgWidth, imgHeight);
for (int pageIndex = 0; pageIndex < doc.PageCount; pageIndex++)
{
int columnIdx;
int rowIdx = Math.DivRem(pageIndex, thumbColumns, out columnIdx);
// Specify where we want the thumbnail to appear.
float thumbLeft = columnIdx * thumbSize.Width;
float thumbTop = rowIdx * thumbSize.Height;
SizeF size = doc.RenderToScale(pageIndex, gr, thumbLeft, thumbTop, scale);
// Draw the page rectangle.
gr.DrawRectangle(Pens.Black, thumbLeft, thumbTop, size.Width, size.Height);
}
img.Save(ExDir + "Rendering.Thumbnails Out.png");
}
}
//ExEnd
}
示例2: RenderToScale
public void RenderToScale()
{
//ExStart
//ExFor:Document.RenderToScale
//ExFor:Document.GetPageInfo
//ExFor:PageInfo
//ExFor:PageInfo.GetSizeInPixels
//ExSummary:Renders a page of a Word document into a bitmap using a specified zoom factor.
Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Rendering.doc");
PageInfo pageInfo = doc.GetPageInfo(0);
// Let's say we want the image at 50% zoom.
const float MyScale = 0.50f;
// Let's say we want the image at this resolution.
const float MyResolution = 200.0f;
Size pageSize = pageInfo.GetSizeInPixels(MyScale, MyResolution);
using (Bitmap img = new Bitmap(pageSize.Width, pageSize.Height))
{
img.SetResolution(MyResolution, MyResolution);
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.
doc.RenderToScale(0, gr, 0, 0, MyScale);
}
img.Save(ExDir + "Rendering.RenderToScale Out.png");
}
//ExEnd
}