Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

iTextsharp, FileStream on Windows Store il2cpp build

Discussion in 'Windows' started by PolosatiyVjih, Feb 15, 2017.

  1. PolosatiyVjih

    PolosatiyVjih

    Joined:
    Apr 5, 2014
    Posts:
    28
    Hey guys, while porting of our app from Android to Windows Store, we have met several problems, one of them is the problem with generating of pdf files on Windows Store.
    First of all, we must stay on il2cpp, not .NET.
    We used iTextSharp library for that, that was working pretty well on android, but seems like isn't work ok on Windows Store.

    The problem is - it saves a pdf file on disk, but doesn't write anything into it, the file stays blank.

    I guess, it might be related with the way iTextSharp work.

    Code (CSharp):
    1.         Document doc = new Document();
    2.         PdfWriter.GetInstance(doc, new FileStream(path + "/" + fileName, FileMode.Create ));
    3. .....

    Here it creates Document object, at path(1st param in FileStream), and uses FileStream to write the data into that document.

    As far as I know, there are is no FileStream on Windows Store build.

    Is there any way how I can resolve that issue?

    There are 4 ways(constructors) to create the document:

    Code (CSharp):
    1. PdfWriter.GetInstance(Document document, Stream os);
    2. PdfWriter.GetInstance(Document document, Stream os, IDocListener listener);
    3. PdfWriter.GetInstance(Document document, Stream os, PdfAConformanceLevel conformanceLevel);
    4. PdfWriter.GetInstance(Document document, Stream os, IDocListener listener, PdfAConformanceLevel conformanceLevel );
    5.  
    but seems like mine one is correct one.

    Is there any way to avoid the problem on il2cpp with that Stream?

    Thanks for help!
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    FileStream should work just fine on IL2CPP builds. The limitations of class not being present are limited to .NET scripting backend.

    Do you get any exceptions? Do you know if it disposes the stream after writing to it? Perhaps the data is just not being flushed?
     
  3. PolosatiyVjih

    PolosatiyVjih

    Joined:
    Apr 5, 2014
    Posts:
    28
    Spent the day today on that, and seems like the problem is not in FileStream, but in System.Drawing that iTextSharp uses, and that is not available on WSA build(according to other forums related regular .NET development and using of itextsharp). It just stops working when it tries to put jpg inside pdf document.

    Also tried to find other frameworks for PDF creation, but none of them works on il2cpp in Unity((

    The only idea I have atm is to use some C++ dll for PDF generation, and call that from Unity, but I guess it may be a big pain to make proper interface, to communicate with that DLL, to tune pdf settings and etc...
    Maybe you can advice smth in that case?:)
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Does it work in the editor? What exactly from System.Drawing does not work?
     
  5. PolosatiyVjih

    PolosatiyVjih

    Joined:
    Apr 5, 2014
    Posts:
    28
    Yea, in Editor all is ok, but on build it just stops working when Im trying to add image on document. I can't see why it is dropping, as itextsharp is dll, but when I do all the same code in editor, or on android, all is ok.

    I know that won't help a lot in troubleshooting, but as is(
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    That sounds like a bug worth reporting.