Ask a Question related to Adobe Acrobat SDK, Design and Development.
-
M_Valentino@adobeforums.com #1
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
-
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... -
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? -
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... -
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... -
Image Text Export
Hello, I'm looking for ideas on how to export an image like this in Fireworks, with no luck so far: ... -
Leonard_Rosenthol@adobeforums.com #2
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
-
M_Valentino@adobeforums.com #3
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
-
Leonard_Rosenthol@adobeforums.com #4
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
-
M_Valentino@adobeforums.com #5
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
-
PDL@adobeforums.com #6
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
-
M_Valentino@adobeforums.com #7
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



Reply With Quote

