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)
- 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
- Fail to draw rectangle to pdf,if rectangle larger than(595x842) HOT 2
- german umlaute diacritic not rendered properly HOT 2
- Make a PDF with an image in memory HOT 4
- Double hex encoding in AbstractContentContext::TJHexLow HOT 3
- Perfectly kosher bug :) HOT 13
- bug: Stack overflow with Invalid PageTree HOT 1
- bug: Stack Overflow when loop in ParseNewObject -> ParseExistingInDirectStreamObject HOT 1
- bug: Requested Allocation Size too big HOT 2
- bug: Heap Use-after-free HOT 1
- bug: Allocation size too big when /Count is high HOT 2
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.