Sample code showing how to use PDFNet SDK from pure C (not via C++)

64 views
Skip to first unread message

Support

unread,
Oct 8, 2009, 2:53:26 PM10/8/09
to PDFTron PDFNet SDK
Q: Could you provide a simple sample in C (not C++) that does
something like open a PDF and save it? I am struggling to see how to
get the equivalent of PDDocOpen(filename) from C working with your
API
(although from C++ it is easy).

--------
A: I didn't find any ready-to-use C code snippet, however direct
translation/lookup from C++ sample gives the following calls:


#include <C/PDF/TRN_PDFNet.h>
#include <C/PDF/TRN_PDFDoc.h>
#include <stdio.h>


// Open a PDF and print out its page count
int main(int argc, char *argv[])
{
int ret = 0;
TRN_Exception ex=TRN_PDFNetInitialize(0);

TRN_PDFDoc doc;
ex=TRN_PDFDocCreateFromFilePath("c:\\my.pdf", &doc);
if(ex!=0) { assert(false); return 1; }

int page_count = 0;
ex=TRN_PDFDocGetPageCount(doc, &page_count);

printf("%d\n", page_count);

ex=TRN_PDFDocDestroy(doc);
if(ex!=0) { assert(false); return 1; }

TRN_PDFNetTerminate();
return 0;
}
Reply all
Reply to author
Forward
0 new messages