簡體   English   中英

在iOS上創建一個包含圖像的簡單XFinium PDF

[英]Creating a simple XFinium PDF on iOS containing an image

我們在iOS上的C#Xamarin Forms應用程序上使用XFinium。 我有一些測試代碼,可以用幾段文字創建一個PDF,它可以正常工作。 但是,當我嘗試包含圖像時,生成的PDF不包含圖像,並且Acrobat Reader給出“此頁面存在錯誤”。 有問題的圖像是我的應用程序中的資源(未從URL加載)。

string path = Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);
string file = System.IO.Path.Combine(path, "report.pdf");
PdfFixedDocument document = new PdfFixedDocument();
PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16);
PdfPage page = document.Pages.Add();
page.Width = 8 * 72 + 36;
page.Height = 11 * 72;
PdfBrush blackBrush = new PdfBrush(PdfRgbColor.Black);
page.Graphics.DrawString("Hello", helveticaBold, blackBrush, 20, 50);
string imageFileName = "UI_Assets_Image.png";
FileStream imageStream = System.IO.File.Open(imageFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
PdfPngImage image = new PdfPngImage(imageStream);
Debug.WriteLine("   image is " + image.Width + " x " + image.Height);
// Reports 1373 x 417 which is correct so I believe it is
// loading the image correctly
// Draw image in the page width
PdfSize size = page.Graphics.DrawImage(image, 36, 75, 540, 166);
Debug.WriteLine("   DrawImage() returned " + size.Width + " x " + size.Height);
// Reports 540 x 166 which seems reasonable
using (FileStream stream = System.IO.File.Create(file))
{
    document.Save(stream, null);
}

如果我不包含圖像,則PDF很好。

出現問題是因為PNG圖像不是正確的PNG圖像,它已在構建過程中進行了優化,以用於iOS方法和類。
如果在項目設置中禁用了PNG優化,則圖像應正確顯示在PDF文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM