• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by DottorFeelgood · Aug 10, 2015 at 08:11 AM · c#pdf

SharpPdf C# generation and display

Hello,

I was trying to figure out how to generate and display a pdf in a Unity app. I would like the app, and pdf to be available for iOS, Android and web app. Following this tutorial I was able to generate a pdf file and store in the app main folder within the simulator.

http://www.devindia.biz/unity-pdf-generation-with-sharppdf-plugin/

Unfortunately when I try to open the pdf inside the app using

 Application.OpenURL("FILE://" + path);

It does not work.

I also tried iTextSharp with poor outcome and I believe it is not free anymore.

Any suggestion would be more than welcome.

Thanx

UPDATE

I partially solved the problem:

I was able to generate the .pdf file in Unity Editor and in Standalone application on OSX. I realized I had trouble on storing/loading files in Unity.

 // this is working on Editor. Application.dataPath are reached by the application and files are stored in Assets/StreamingAssets folder under project in Editor     
 
        #if UNITY_EDITOR || UNITY_EDITOR_64 
         myDoc.createPDF(Application.dataPath + "/StreamingAssets/" + attacName);
 
         
         myTable = null;
 
         #endif

 // This is working on Mac standalone application. The file is correctly saved under Application.app/Contents folder

   #if UNITY_STANDALONE
         
     myDoc.createPDF(Application.dataPath + "/" + attacName);
     myTable = null;
         #endif

The code to retrieve and open the file:

 public void openPdf() {
     string path;

         // tested working on mac
 
         #if UNITY_EDITOR || UNITY_EDITOR_64
 
         
         path = "file:" +Application.dataPath + "/StreamingAssets/" + attacName;
 
 
         #endif
 
         #if UNITY_STANDALONE
         
          path = "file:" +Application.dataPath + "/" + attacName;
         
         #endif
 
         Application.OpenURL(path);
         Debug.Log ("Button Clicked");
 
     }

So far everything works perfectly.

The pain comes with ios.

I was able to generate a pdf file with the above code in Application.persistentDataPath and getting it back from iTunes (to verify it was created) enabling UIFileSharingEnabled under info.plist. Here's the code:

    #if UNITY_IOS 
       myDoc.createPDF(Application.persistentDataPath + "/" + attacName);
       myTable = null;
     #endif

The trouble is when I try to Application.OpenUrl(path). It seems that c# code is blind to Application.persistentDataPath. Which by the way is /var/mobile/Containers/Data/Application/"ApplicationName"/Documents/"pdfName".pdf using

 path = "file://" + Application.persistentDataPath + "/" + attacName;
     Application.OpenURL(path);

I tried also to save the file in StreamingAssets folder but Xcode didn't like it:

UnauthorizedAccessException: Access to the path "/private/var/mobile/Containers/Bundle/Application/F105683E-B2EA-4B0C-81B7-61302C58D56C/PdfReader.app/Data/newPDF.pdf" is denied. at Mono.Security.Cryptography.RSAManaged.GenerateKeyPair () [0x00000] in :0 at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in :0 at System.IO.FileStream..ctor (System.String path, FileMode mode) [0x00000] in :0 at sharpPDF.pdfDocument.createPDF (System.String outputFile) [0x00000] in :0 at simplepdf+c__Iterator1.MoveNext () [0x00000] in :0

(Filename: currently not available on il2cpp Line: -1)

I then decided to get this wrapper

https://www.assetstore.unity3d.com/en/#!/content/17591

but it can only copy already formatted pdf file from StreamingAssets folder to /Raw folder on iOS device.

I am thinking I have to write my own wrapper to load data from Application.persistentDataPath on iOS, have you got any suggestion to start with?

Thank you again.

Comment
kayy

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by fashrista · Oct 24, 2018 at 12:40 PM

@ DottorFeelgood I donno if this helps, but on android I had to add a AndroidManifest.xml with all the permisions. It goes like this:

 <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
   <intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
     <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
   </intent-filter>
   <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
 </activity>
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Mad_26 · Jun 21, 2019 at 10:36 AM

I know I am posting offtopic question here , since i was unable to find any post regarding the sharp pdf with unity3d I am using the sharp pdf package with unity3d and i am facing difficulties for windows platform like: 1. How to dynamically increase the column height according to the text size at runtime. 2. How do i insert an image without using the co-routine function. 3. How to dynamically write the data on the new page if current page is filled and data is still pending. For example, there are 50 rows in my table at runtime and one first page 30rows occupy the space, then how do i dynamically write the remaining 20 rows on second page. 4. Instead of storing the file in root folder, in assets folder , how can i store the pdf at different location by selecting the folder from the system.

Can anyone please help me out, it would be great help....Thank you in advance.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Initialising List array for use in a custom Editor 1 Answer

How can I create a PDF while playing my games build and then display it to the player ? 1 Answer

Advanced Unity C# Ebooks 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges