1

我一直在使用 sharpPDF API 来尝试在 Unity3D 中创建 pdf 图像。hello world 测试进行得很顺利,但无论我做什么,我都无法让图像正常工作。使用 ddImage 函数会使 pdf 阅读器崩溃,而使用 newAddImage 似乎什么也没做。不幸的是,谷歌根本没有帮助,所以我希望这里有人可以帮助我!

我确实查看了一个不同的库,但是 pdfsharp 只是简单地没有工作,在编译器上给出了大量的错误,而且 iTextSharp 很昂贵。

API 在这里http://www.francescogallorini.com/2011/02/unity-sharp-pdf/

我的代码是:

    //byte[] image;
    //image = File.ReadAllBytes("Assets/Sprites/128x128 player ship trial.png");

    pdfDocument myDoc = new sharpPDF.pdfDocument("Awesome Space Station", "Al Wyvern");
    pdfPage myPage = myDoc.addPage(500,500);
    myPage.newAddImage("Assets/Sprites/128x128 player ship trial.png", 10, 10);
    //myPage.addImage(image, 0,0,256,256);
    myPage.addText("Hello World", 128, 128, predefinedFont.csCourier, 20);
    myDoc.createPDF("Awesome Space Station.pdf");
    myPage = null;
    myDoc = null;

谢谢你提供的所有帮助

4

1 回答 1

0
// in your poco
public string HeaderImage { get; set; } =
    Path.GetDirectoryName(Path.GetDirectoryName(
        System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName()
            .CodeBase))) + "\\assets\\your_logo.png";

// then in your function
myDoc.addImageReference(HeaderImage.Replace("file:\\", string.Empty), "Logo");
        pdfPage.addImage(myDoc.getImageReference("Logo"), 13, 720, 60, 60);
于 2018-08-13T20:57:27.987 回答