简体   繁体   中英

How to add android pdf writer to android project

I want to add library, android pdf writer to my project to create pdf documents in the app. Below link has some files associated with the library. http://sourceforge.net/p/apwlibrary/code/HEAD/tree/

I would like to know, 1. How do I access/add these files to my project? 2. Since I only want to generate a pdf document there is a file in there called PDFWriterDemo.java, could I just add that to my project or do I have to add all the files in the library?

Sorry I couldn't find the documentation on how to add them to project to use these files. Thanks

There is no jar file. You have to embed source files directly. You should include all the source files except for:

  • APW.pdf
  • PDFWriterDemo.java
  • assets.zip
  • helloworld.pdf
  • README.txt

You don't need any additional jar file.

I write detailed instruction here: http://karino2.livejournal.com/293016.html

(Using AS 1.2 Beta at time of writing)

You first need to download the source code since there is no jar. To do that:

  • Go to the link that you provided and click on "Download Snapshot".
  • Unzip the file you just downloaded into a new folder
  • Remove all of the files that are not Java files (they aren't necessary)

Then, to add it to your project, it depends on if you are using Gradle.

  1. With Gradle
    • In Android Studio, click on Project Settings
    • Click on the plus sign to add a new module
    • Click on Android Library
    • Choose whatever name you want for the application and module name (AndroidPDFWriter is pretty consistent) but make sure that the package name matches the library's package name (crl.android.pdfwriter)
    • Choose No Activity on the next page and press finish to create the module.
    • Copy the sources from the folder with the source code into that new module (make sure to copy it in the right directory, ie src/main/java/crl.android.pdfwriter)

From there, an Android module is created with all of the necessary resources. I chose to delete all of the extra file that AS creates for you but that's your call. Make sure to keep the manifest (I emptied it though to just have the Manifest tag since nothing else was useful). You can then declare the dependency on this module from your main one like you would normally.

  1. Without Gradle
    • In Android Studio, click on Project Settings
    • On the modules page, click on the plus sign to add a new module
    • Click on Import Module
    • Choose the folder with all of the sources that you had unzipped.
    • Go through the following pages of the import module process normally.

From there, the Android module is created (make sure that the Module SDK is an Android one) and you can add a dependency the normal way as well.

This isn't the best way to do things, but I see no alternative for this particular library. Hope this helps !

Get the jar file and add to your project. Just adding PDFWriterDemo.java will not work as this class has dependency on other classes like Page and you might have to include all of them.

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile files('libs/xyz.jar') } Assuming you are using Android Studio, follow these steps to include .jar into project:

  1. Get the jar file.
  2. Put the jar into the libs folder
  3. Right click it and hit 'Add as library'
  4. Ensure that compile files is in your build.gradle file, in the dependencies add the below.

.

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/xyz.jar') //xyz.jar is the filename of your jar
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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