addImage not working in SharpPDF

1.8k views Asked by At

I've been using the sharpPDF API to try and create pdf images inside Unity3D. 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. 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.

API is here 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

1

There are 1 answers

0
Phillip Holmes On
// 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);