透過 FreeSpire.Office 轉成 PDF 後紙張設定會跑掉,例如 A5 變A4、 橫向變直向
以 Spire.PDF 讀入資料並轉成另一個 PDF 同時重設紙張設定
document.SaveToStream(memStreamPDF, Spire.Doc.FileFormat.PDF); // 以 Spire.Doc 為例
using (var pdf = new PdfDocument(memStreamPDF))
using (var newPdf = new PdfDocument()) {
foreach (PdfPageBase page in pdf.Pages) {
PdfPageBase newPage = newPdf.Pages.Add(PdfPageSize.A5, new PdfMargins(0), PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);
PdfTextLayout loLayout = new PdfTextLayout();
loLayout.Layout = PdfLayoutType.OnePage;
page.CreateTemplate().Draw(newPage, new System.Drawing.PointF(0, 0), loLayout); } newPdf.SaveToStream(memStreamPDF);
...
}
※多頁word 轉PDF 會有問題,且格式會有出入,調整紙張格式也不成功,目前不建議把word轉成PDF
using (var pdf = new PdfDocument(memStreamPDF))
using (var newPdf = new PdfDocument()) {
foreach (PdfPageBase page in pdf.Pages) {
PdfPageBase newPage = newPdf.Pages.Add(PdfPageSize.A5, new PdfMargins(0), PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);
PdfTextLayout loLayout = new PdfTextLayout();
loLayout.Layout = PdfLayoutType.OnePage;
page.CreateTemplate().Draw(newPage, new System.Drawing.PointF(0, 0), loLayout); } newPdf.SaveToStream(memStreamPDF);
...
}
※多頁word 轉PDF 會有問題,且格式會有出入,調整紙張格式也不成功,目前不建議把word轉成PDF
留言