Export to XML or Text in C# using SDK 9

Ask a Question related to Adobe Acrobat SDK, Design and Development.

  1. #1

    Default Export to XML or Text in C# using SDK 9

    I'm stumped on how to proceed with this. What I'd like to do is open a PDF file in code and save it out either as XML or as text. By looking at the API documentation, I can't quite figure it out.

    I've found some examples that say I should call GetJSObject() as I did below, but none of the properties or methods exist on the object that are in the examples.

    Any help is appreciated!

    string document = @"C:\temp\test.pdf";
    string documentTitle = String.Empty;
    int numOfPages;

    CAcroApp mApp = new AcroAppClass();
    CAcroAVDoc avDoc = new AcroAVDocClass();
    CAcroPDDoc pdDoc;
    if (avDoc.Open(document, ""))
    {
    pdDoc = (CAcroPDDoc)avDoc.GetPDDoc();
    Object jsAcroObj = pdDoc.GetJSObject();
    numOfPages = pdDoc.GetNumPages();
    documentTitle = pdDoc.GetFileName();
    Console.WriteLine("Opened: " + documentTitle);
    Console.WriteLine("Number of pages: " + numOfPages.ToString());
    }
    else Console.WriteLine("Cannot open: " + document);
    M_Valentino@adobeforums.com Guest

  2. Similar Questions and Discussions

    1. Export text from ID CS
      I would like to export text from InDesign, but the only option for this I get is Adobe InDesign Tagged Text. Apparently .txt (ascii text) and .rtf...
    2. How to Export Text on a Path to PS
      Is there a way to export text from Illustrator to PS so that it retains it's characteristics (Font, color, etc.) and so that it remains editable text?
    3. Export text to WMF
      I'm learning my first lessons with Illustrator 10. I have a created a simple logo that includes some text. I'd like to save it as *.wmf in order to...
    4. Missing text (flush right text block) upon export to pdf
      I was aghast today to see and ad in the local paper (that I worked on and got client approval for) missing text at bottom of ad. I am using FH 10 in...
    5. Image Text Export
      Hello, I'm looking for ideas on how to export an image like this in Fireworks, with no luck so far: ...
  3. #2

    Default Re: Export to XML or Text in C# using SDK 9

    Have you download the Acrobat SDK, read the documentation and reviewed the supplied sample code?

    That's where you need to start.
    Leonard_Rosenthol@adobeforums.com Guest

  4. #3

    Default Re: Export to XML or Text in C# using SDK 9

    Yes, that is how I started. That's how I got this far, but I'm finding the documentation to be both unclear and incomplete. For example, when I call GetJSObject(), what type of object is returned? I can't find that. If I could, I might be able to determine why jsAcroObj in my example doesn't have any Acrobat-related properties or methods, probably just by casting it to the correct type.

    I also did a good amount of searching via Google without much in the way of answers.

    Which type does GetJSObject() return and should it have a SaveAs() method?
    M_Valentino@adobeforums.com Guest

  5. #4

    Default Re: Export to XML or Text in C# using SDK 9

    Did you look at the sample of the use of GetJSObject in the SDK? Read the documentation about how it works? It's all in there!

    (remember that JSObject is a "virtual" object)
    Leonard_Rosenthol@adobeforums.com Guest

  6. #5

    Default Re: Export to XML or Text in C# using SDK 9

    This is a quote from the SDK that I read too quickly earlier and I think this is the source of my problem:

    "You may have a few questions after studying the code. For example, why is jso declared as an Object, while gApp and gPDDoc are declared as types found in the Acrobat type library? Is there a real type for JSObject?

    The answer is no, JSObject does not appear in the type library, except in the context of the CAcroPDDoc.GetJSObject call. The COM interface used to export JavaScript functionality through JSObject is known as an IDispatch interface, which in Visual Basic is more commonly known simply as an 'Object' type. This means that the methods available to the programmer are not particularly well-defined."

    Even though I'm working in C#, this sounds like why I wouldn't see the properties/methods I was expecting. Unfortunately, now I have to wait until Monday morning to try this out!
    M_Valentino@adobeforums.com Guest

  7. #6

    Default Re: Export to XML or Text in C# using SDK 9

    Please see the following thread about calling JSObject methods from C#:
    <http://www.adobeforums.com/webx/.59b6b448/0>
    PDL@adobeforums.com Guest

  8. #7

    Default Re: Export to XML or Text in C# using SDK 9

    Thanks PDL and Leonard. I was able to get the basics of what I wanted, though I'm still working on the code. I switched to text output. Here's what I have so far:

    CAcroAVDoc avDoc = new AcroAVDocClass(); //set AVDoc object
    CAcroPDDoc pdDoc;
    try
    {
    if (avDoc.Open(document, "")) //open the PDF
    {
    pdDoc = (CAcroPDDoc)avDoc.GetPDDoc();
    Console.WriteLine("File: " + pdDoc.GetFileName() + ", Pages: " +
    pdDoc.GetNumPages().ToString());
    Object jsAcroObj = pdDoc.GetJSObject();
    Type T = jsAcroObj.GetType();
    Console.WriteLine("\tStarting export.");
    object[] saveAsParam = { documentText,
    "com.adobe.acrobat.accesstext" };
    T.InvokeMember("saveAs",
    BindingFlags.InvokeMethod |
    BindingFlags.Public |
    BindingFlags.Instance,
    null, jsAcroObj, saveAsParam);
    object[] closeDocParam = { true };
    T.InvokeMember("closeDoc",
    BindingFlags.InvokeMethod |
    BindingFlags.Public |
    BindingFlags.Instance,
    null, jsAcroObj, closeDocParam);
    Console.WriteLine("\tExport complete.");

    if (avDoc.Close(1) != true) avDoc.Close(1);
    }
    else Console.WriteLine("Cannot open: " + document);
    }
    catch (Exception ex)
    {
    // TODO: Log to file.
    }
    M_Valentino@adobeforums.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139