[英]xfinium: How To generate PDF with differant orientations
我嘗試創建一個帶有頁眉和頁腳的 PdfFlowDocument。 縱向模式下從 1 到 3 的頁面。 第 4 頁是橫向的,其余的又是縱向的。 按照我的代碼片段:
PdfFlowDocument flowDocument = new PdfFlowDocument();
//flowDocument.HeadersFooters.EvenPagesHeader = docHeader;
//flowDocument.HeadersFooters.EvenPagesFooter = docFooter;
Xfinium.Pdf.Core.PdfFile sourceFile = new Core.PdfFile(File.OpenRead(""));
Xfinium.Pdf.Graphics.PdfPageContent[] pageContents = sourceFile.ExtractPageContent(0, sourceFile.PageCount - 1);
foreach (Xfinium.Pdf.Graphics.PdfPageContent content in pageContents)
{
//content can be Portrait or Landscape
//How can I rotate the orientation?
//How can I scale the page?
var flowContent = new Xfinium.Pdf.FlowDocument.PdfFlowFormXObjectContent(content);
flowDocument.AddContent(flowContent);
}
您處理 PageCreated 事件並根據您的特定條件將頁面旋轉設置為橫向 90。
PdfFlowDocument flowDocument = new PdfFlowDocument();
flowDocument.PageCreated += FlowDocument_PageCreated;
//flowDocument.HeadersFooters.EvenPagesHeader = docHeader;
//flowDocument.HeadersFooters.EvenPagesFooter = docFooter;
Xfinium.Pdf.Core.PdfFile sourceFile = new Core.PdfFile(File.OpenRead(""));
Xfinium.Pdf.Graphics.PdfPageContent[] pageContents = sourceFile.ExtractPageContent(0, sourceFile.PageCount - 1);
foreach (Xfinium.Pdf.Graphics.PdfPageContent content in pageContents)
{
//content can be Portrait or Landscape
//How can I rotate the orientation?
//How can I scale the page?
var flowContent = new Xfinium.Pdf.FlowDocument.PdfFlowFormXObjectContent(content);
flowContent.SizeIsRelativeToAvailableSpace = true;
flowContent.FormXObjectHeight = 100;
flowContent.FormXObjectWidth = 100;
flowDocument.AddContent(flowContent);
}
private void FlowDocument_PageCreated(object sender, PdfFlowPageCreatedEventArgs e)
{
if (yourConditionHere)
{
e.Page.Rotation = 90;
}
}
更新:您可以將flowContent.SizeIsRelativeToAvailableSpace
屬性設置為 true, flowContent.FormXObjectWidth
和flowContent.FormXObjectHeight
屬性設置為 100。這意味着內容對象將被縮放以占用所有可用空間 (100%)。 它還將處理白頁問題。
免責聲明:我為開發XFINIUM.PDF庫的公司工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.