Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
Allow setting of title in PDF metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtheis committed Aug 23, 2015
1 parent 42bde29 commit 9e99699
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testAddPageToDocument() throws IOException {
+ pdfBasename);

// Start the PDF writing process.
boolean beginSuccess = baseApi.beginDocument(pdfRenderer);
boolean beginSuccess = baseApi.beginDocument(pdfRenderer, "title");
// assertTrue(beginSuccess);

// Add a page to the PDF.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,7 @@ bool TessBaseAPI::ProcessPagesFileList(FILE *flist,
}

// Begin producing output
const char* kUnknownTitle = "";
if (renderer && !renderer->BeginDocument(kUnknownTitle)) {
if (renderer && !renderer->BeginDocument(unknown_title_)) {
return false;
}

Expand Down Expand Up @@ -1162,8 +1161,7 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
}

// Begin the output
const char* kUnknownTitle = "";
if (renderer && !renderer->BeginDocument(kUnknownTitle)) {
if (renderer && !renderer->BeginDocument(unknown_title_)) {
pixDestroy(&pix);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,12 @@ class TESS_API TessBaseAPI {
int timeout_millisec,
TessResultRenderer* renderer,
int tessedit_page_number);
// There's currently no way to pass a document title from the
// Tesseract command line, and we have multiple places that choose
// to set the title to an empty string. Using a single named
// variable will hopefully reduce confusion if the situation changes
// in the future.
const char *unknown_title_ = "";
}; // class TessBaseAPI.

/** Escape a char string - remove &<>"' with HTML codes. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TESS_API TessResultRenderer {
bool EndDocument();

const char* file_extension() const { return file_extension_; }
const char* title() const { return title_; }
const char* title() const { return title_.c_str(); }

/**
* Returns the index of the last image given to AddImage
Expand Down Expand Up @@ -126,7 +126,7 @@ class TESS_API TessResultRenderer {

private:
const char* file_extension_; // standard extension for generated output
const char* title_; // title of document being renderered
STRING title_; // title of document being renderered
int imagenum_; // index of last image added

FILE* fout_; // output file pointer
Expand Down
15 changes: 13 additions & 2 deletions tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,21 @@ void Java_com_googlecode_tesseract_android_TessPdfRenderer_nativeRecycle(JNIEnv

jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeBeginDocument(JNIEnv *env,
jobject thiz,
jlong jRenderer) {
jlong jRenderer,
jstring title) {

const char *c_title = env->GetStringUTFChars(title, NULL);
tesseract::TessPDFRenderer* pdfRenderer = (tesseract::TessPDFRenderer*) jRenderer;
return pdfRenderer->BeginDocument("");

jboolean res = JNI_TRUE;

if (pdfRenderer->BeginDocument(c_title)) {
res = JNI_FALSE;
}

env->ReleaseStringUTFChars(title, c_title);

return res;
}

jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeEndDocument(JNIEnv *env,
Expand Down
18 changes: 16 additions & 2 deletions tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -856,11 +856,25 @@ protected void onProgressValues(final int percent, final int left,

/**
* Starts a new document. This clears the contents of the output data.
*
* Caller is responsible for escaping the provided title.
*
* @param title a title to be used in the document metadata
* @return {@code true} on success. {@code false} on failure
*/
public boolean beginDocument(TessPdfRenderer tessPdfRenderer, String title) {
return nativeBeginDocument(tessPdfRenderer.getNativePdfRenderer(),
title);
}

/**
* Starts a new document with no title.
*
* @return {@code true} on success. {@code false} on failure
* @see #beginDocument(TessPdfRenderer, String)
*/
public boolean beginDocument(TessPdfRenderer tessPdfRenderer) {
return nativeBeginDocument(tessPdfRenderer.getNativePdfRenderer());
return nativeBeginDocument(tessPdfRenderer.getNativePdfRenderer(), "");
}

/**
Expand Down Expand Up @@ -963,7 +977,7 @@ private native void nativeSetImageBytes(

private native int nativeStop();

private native boolean nativeBeginDocument(long rendererPointer);
private native boolean nativeBeginDocument(long rendererPointer, String title);

private native boolean nativeEndDocument(long rendererPointer);

Expand Down

0 comments on commit 9e99699

Please sign in to comment.