【问题标题】:Creating PDF works on Unity (Windows) but not on a android device创建 PDF 适用于 Unity (Windows) 但不适用于 Android 设备
【发布时间】: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


【解决方案1】:

感谢您的帮助。

使用 "Path.Combine(Application.persistentDataPath, "HelloWorld_tempfile.pdf")" 我得到了相同的结果。也许 ZetPDF 无法在移动设备上使用?

我尝试使用 sharpPDF,他的方法“createPDF()”在我的平板电脑上运行。

我推荐它^^

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 2018-09-01
    • 1970-01-01
    相关资源
    最近更新 更多