【发布时间】:2020-11-02 17:07:33
【问题描述】:
我使用此代码创建和写入 PDF:
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with ZetPDF";
// Create an empty page
PdfPage page = document.AddPage();
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
// Create a font
XFont font = new XFont("Times New Roman", 20, XFontStyle.BoldItalic);
// Draw the text
gfx.DrawString(test, font, XBrushes.Black,
new XRect(10, 0, page.Width, page.Height),
XStringFormats.TopLeft);
const string filename = "HelloWorld_tempfile.pdf";
document.Save(filename);
它在 Unity 中完美运行,但是当我作为 APK 导出到 android 设备时没有任何反应。
我想我必须为路径添加一个带有持久数据的命令,等等。就像我过去用来创建 XML 文件一样。
但是如何处理 PDF 文件? 我的代码中缺少什么?
【问题讨论】:
-
document.Save(filename);究竟想写入什么路径?你可能没有 Andoird 的权限 -
document.Save(filename);应该保存在哪里?难道你必须提供一个完整的路径? -
嗯,我试图改变:string filename = Application.persistentDataPath+"HelloWorld_tempfile.pdf";文档.保存(文件名);但什么都没有改变。我想在默认文件夹 com.app 中创建他
-
好吧
Application.persistentDataPath+"HelloWorld_tempfile.pdf"将是一个无效的文件路径(缺少文件路径分隔符)......你应该尝试例如Path.Combine(Application.persistentDataPath, "HelloWorld_tempfile.pdf") -
能否也包含完整的代码?您使用的是什么
PdfDocument课程?有没有可能它根本不存在于 Android 上?
标签: c# android unity3d pdf write