Comments (3)
I found the general help from Android documentation to be helpful:
https://developer.android.com/studio/projects/add-native-code
Since PDFWriter is a Cmake project it can be easily incorporated into a new or existing application.
there's several ways to go about this, but i find the simplest is to add a new native C++ library to your project, which will involve having a new CMakeList.txt file and some native code. In that CMakeLists.txt refer to pdf-writer, and then write code in the native library to do whatever you want with pdf-writer.
So for example if one uses the "Native C++" project template you can add the following steps and have pdf-writer available for you:
1. Edit the CMakeLists.txt to fetch PDF-Writer from github
In the CMakeLists.txt file of the native-lib add the following statement to fetch pdf-writer:
# hummus dependency
include(FetchContent)
FetchContent_Declare(
PDFHummus
GIT_REPOSITORY https://github.com/galkahana/PDF-Writer.git
GIT_TAG v4.5.7
)
FetchContent_MakeAvailable(PDFHummus)
2. Add pdf-writer dependency to your native library
Still in the CMakeLists.txt file of the native-lib add this statement to link pdf-writer to your library and make includes and links available:
target_link_libraries (mynativeapplication PDFHummus::PDFWriter)
(change mynativeapplication
to the name used in add_library
).
3. Add code in the exported function(s) to use PDF-Writer
for example, in the native app template i added the code in the native-lib.cpp.
here's the full code example, it creates an empty file:
#include <jni.h>
#include <string>
#include "PDFWriter.h"
#include "PDFPage.h"
#include "PDFRectangle.h"
#include <iostream>
using namespace std;
using namespace PDFHummus;
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_mynativeapplication_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
// build me an empty PDF
PDFWriter pdfWriter;
EStatusCode status;
do
{
status = pdfWriter.StartPDF("./EmptyPages.pdf",ePDFVersion14);
if(status != PDFHummus::eSuccess)
{
cout<<"failed to start PDF\n";
break;
}
PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0,0,595,842));
for(int i=0;i<4 && PDFHummus::eSuccess == status;++i)
{
status = pdfWriter.WritePage(page);
if(status != PDFHummus::eSuccess)
cout<<"failed to write page "<<i<<"\n";
}
delete page;
status = pdfWriter.EndPDF();
if(status != PDFHummus::eSuccess)
{
cout<<"failed in end PDF\n";
break;
}
}while(false);
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
This should create a file...somewhere (i guess pointing to a clear place in the device would be better...but it's just an example, so i allowed it).
I'm guessing similar thing can be done for other usages.
Having said that
I'm kinda positive there are Java PDF libraries, no? nothing that can be used instead that might make this simpler? though i guess it doesn't look very complicated. I hear PDFBox is quite good, if you are interested in looking for an alternative.
from pdf-writer.
Can be helpful but noy exactly because my goal is developing a crossplatform Unreal Engine plugin. So, there is no Android Studio project at all. I need a gradlew assembleRelease like solution to give me .so files
from pdf-writer.
I see. I think this is covered by adding and externalNativeBuild statement to your gradle:
https://developer.android.com/studio/projects/gradle-external-native-builds#configure-gradle
The studio just makes it easy in creating a local cmake project for you that you can tie to pdf-,writer. The end result is an so library.
But yeah im no android/gradle expert so maybe it doesn't help
from pdf-writer.
Related Issues (20)
- Can not modify a document by creating a new form XObject and using it in one of the pages HOT 3
- [Question] - pdf to image HOT 1
- Question about attachments HOT 2
- some example projects in wiki are missing HOT 2
- Streams objects writing problem HOT 2
- Add watermark to PDF HOT 7
- Missing lib.obj file HOT 3
- CIDSet encoding does not conform with ISO 19005-2:2011, ISO 19005-3:2012 (PDF/A-2b or PDF/A-3b) HOT 21
- annotations are lost with PDFDocumentCopyingContext::AppendPDFPageFromPDF HOT 3
- How to draw Bezier curves using PDF-Witer library? HOT 2
- Parse a screenplay into scene objects? HOT 2
- color emojis HOT 16
- Links are removed when documents are merged HOT 8
- Color inversion problem occurs when exporting images HOT 1
- infinite loop HOT 2
- Crash when WriteUsedFontsDefinitions HOT 17
- Publish to github releases without PDFWriterTesting HOT 4
- U3D support, 10 years later HOT 10
- `Segmentation fault (core dumped)` just for adding `PDFWriter pdfWriter` in the `h` file HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdf-writer.