简体   繁体   English

addImage在SharpPDF中不起作用

[英]addImage not working in SharpPDF

I've been using the sharpPDF API to try and create pdf images inside Unity3D. 我一直在使用SharpPDF API尝试在Unity3D中创建pdf图像。 The hello world test went fine but no matter what I do I can't get images to work. 你好世界测试很好,但是无论我做什么我都无法使图像工作。 Using the ddImage function makes the pdf reader crash and using newAddImage seems to do nothing at all. 使用ddImage函数会使pdf阅读器崩溃,并且使用newAddImage似乎什么都不做。 Unfortunately google has been no help at all so I'm hoping someone here can help me out! 不幸的是,谷歌根本没有帮助,所以我希望这里有人可以帮助我!

I did look into a different library but pdfsharp just plain didn't work giving a ton of errors on the compiler and iTextSharp is to expensive. 我确实调查了一个不同的库,但是pdfsharp只是简单的无法在编译器上产生大量错误而iTextSharp是昂贵的。

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

and my code is: 我的代码是:

    //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;

Thanks for any help you can give 谢谢你提供的所有帮助

// 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM