Skip to main content
Participant
May 12, 2023
Question

C#でpdfをtifに変換したいです

  • May 12, 2023
  • 1 reply
  • 1172 views

C#でpdfをtifに変換したいです

private void button1_Click(object sender, EventArgs e)
{
Acrobat.CAcroPDDoc doc = null;

if (doc.Open(@"D:\00000001.pdf"))
{
Object jso = doc.GetJSObject();
object[] arguments = new object[] { @"D:\00000001.tif", "com.adobe.acrobat.tiff" };
Object objresult = jso.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, jso, arguments);
}
}

上記コードを実行するとacrobatが立ち上がり「ファイル書き込み中にエラーが発生しました。
ディスク容量が不足している可能性があります。」とエラーが出てしまい変換に失敗します。

なぜこのような現象が出るのかが判りません。原因と対策をご教示頂きたいです。

 

This topic has been closed for replies.

1 reply

Inspiring
May 15, 2023

以下のコード確認してみました。

        // Testボタン
        private void buttonTest_Click(object sender, EventArgs e)
        {
            // Acrobat Application
            dynamic acroApp = Activator.CreateInstance(Type.GetTypeFromProgID("AcroExch.App"));
            if (acroApp != null)
            {
                // PDDoc
                dynamic acroPDDoc = Activator.CreateInstance(Type.GetTypeFromProgID("AcroExch.PDDoc"));
                if (acroPDDoc != null)
                {
                    // open
                    if (acroPDDoc.Open(@"C:\Work\Test.pdf"))
                    {
                        // JSObject
                        Object jsObject = acroPDDoc.GetJSObject();
                        if (jsObject != null)
                        {
                            object[] arguments = new object[] { @"C:\Work\Test.tiff", "com.adobe.acrobat.tiff" };
                            Object objresult = jsObject.GetType().InvokeMember("saveAs", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, jsObject, arguments);
                        }
                    }
                }
            }
            return;
        }

これで、Tiff保存できています。

 

Acrobat JavaScriptのSafe pathの可能性もあるので、Tiffの保存ディレクトリを、D:\ではなくサブディレクトリ以下にして試してみて下さい。

→本来のエラーは、NotAllowedErrorなので、違うかもしれません。

 

Acrobat JavaScriptのSafe path

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html

====

Safe path


Acrobat 6.0 introduced the concept of a safe path for JavaScript methods that write data to the local hard drive based on a path passed to it by one of its parameters.

A path cannot point to a system critical folder, for example a root, windows or system directory. A path is also subject to other unspecified tests.

For many methods, the file name must have an extension appropriate to the type of data that is to be saved. Some methods may have a no-overwrite restriction. These additional restrictions are noted in the documentation.

Generally, when a path is judged to be not safe, a NotAllowedError exception is thrown (see Error object) and the method fails.

====

 

 

 

 

 

Participant
May 15, 2023

戻り橋様

 

ご連絡ありがとうございます。

いただいたソースをコピペし実行しましたがエラーは変わらず、下記が発生しました。

acrobatが立ち上がり「ファイル書き込み中にエラーが発生しました。
ディスク容量が不足している可能性があります。」とエラーが出てしまい変換に失敗します。

パスは変更せずC:\workにしております。

ちなみにですがインストールしているのはadobe acrobat proです。

 

ヒントをいただけたので自分でもう少し調べてみようと思います。

さらにご意見いただけるならばお願いいたします。

ありがとうございました。