Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Printing in unity

Discussion in 'Editor & General Support' started by EducaSoft, Sep 11, 2007.

  1. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Hi there,

    I have a need to print text and graphics from within my programs. As I create educational software its mostly wishfull to be able to print out evaluation sheets or even exercise sheets with math exercices.

    Previously I worked with coding on windows and my programming language was delphi.
    There we could do things like

    Printer.BeginDoc;
    Printer.Newpage;
    Printer.Font.Name:='Arial';
    Printer.Font.Size:=14;
    Printer.TextOutXY(50,50,'Hello world');
    Printer.DrawImage(50,50,100,100,'logo.gif');
    Printer.EndDoc;


    This way we could easily print whatever we want to the windows printer.

    Is such a thing possible in unity by any means ? I may have understood that it is not possible by default, but maybe there are workarounds ? Plugins maybe ?

    I really hope that somebody could help me out a little here. I am not looking for way to print a screenshot of my unity game, but merely being able to print text and gfx to certain portions of the page is what I'm looking for.


    If anyone has more information, then its heavily welcome.

    If somebody from Otee Staff looks at it, then maybe this could be a very welcome new feature for 2.1 ???
    I don't think that its technically very difficult to implement. At least on Windows its not so why should it be on Mac.


    Thanks in advance for any possible info/help
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,749
    This sounds like a job for a C++ plugin.

    I don't think it'd make much sense to incorporate it into Unity itself - it'd only bloat the runtime (and the web player download size) for a feature that won't be used in 99.9% of games. Further, because this functionality isn't heavily intertwined with the engine itself, it should be fairly easy to port some code from elsewhere into a plugin.
     
  3. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    I can understand your point.
    On the one hand you are telling now that unity is a tool to make GAMES. In my opinion Unity is a development tool and everybody can decide WHAT to make.

    But you might be right. 99% is games.

    Lets rephrase my question.
    Is there anyone who has knowledge about c++ plugins who could tell me if this isn't too complicated?
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    I am pretty sure that you can start a printing job using Cocoa in less than 40 lines of C++ code in a plugin. I don't know about printing on the windows side.
     
  5. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
  6. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Hmmm,

    On http://unity3d.com/Documentation/Manual/Plugins.html I found that windows plugins are simply DLL files with a public interface.

    This sounds nice.
    So standalone applications can call functions in windows DLLs ? (on win platform of course)
    That would solve my printing problem since I can then make a tool which can generate both PDF and print in such a DLL.

    On the mac side is another question, but Joachim allready pointed me in the good direction. Tnx
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Correct. On Windows they are DLLs with a C interface, and on Mac OS X they are shared libraries (same concept as DLLs actually) with a C interface.

    So the only tricky thing is marshaling complex data between the script and the plugin (like if you want to pass a hashtable, you'd have to do some work to lay it out into a marshallable array).
     
  8. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    This is really powerfull as printing is very important to me.
    But on the windows part I think I can make such a DLL in maybe 2 hours. On Mac side it'll require some help since I never coded mac before yesterday, but it surely must be possible.
     
  9. bronxbomber92

    bronxbomber92

    Joined:
    Nov 11, 2006
    Posts:
    888
    I know you can create PDF files using Quartz or Cocoa. Using Cocoa would require C++ and Objective-C code, which you may not be as familiar with.

    Here' how to actually print documents using Cocoa: http://developer.apple.com/documentation/Cocoa/Conceptual/Printing/index.html

    Here is PDF kit for Objective-C (which I think wraps around Quartz): http://developer.apple.com/documentation/GraphicsImaging/Conceptual/PDFKitGuide/index.html

    Edit - Maybe System.Drawing.Printing is supported my Mono? http://www.go-mono.com/docs/ (then navigate to it..)