0

.net アプリケーションを使用して、最初の行または最初の単語を少し下に移動して、pdf ドキュメントを変更したいと考えています。

プログラムでpdfドキュメントのテキスト位置を変更するのに役立つライブラリはありますか?

PDF 上のテキスト オブジェクトの y 位置を変更したい。この操作は多くのファイルに対して行われ、svg や word への変換などの中間プロセスを使用したくない。PDF を直接変更したいファイル。

PdfSharp 、 iTextSharp 、 PDFLibNet 、 Amyuni、pdfclown などのいくつかのライブラリをチェックしましたが、この問題の解決策が見つかりませんでした。

4

2 に答える 2

1

pdfファイル上のテキストオブジェクトを移動するための解決策を1か月以上研究して、[Docotic、pdfclown、iTextSharp、PdfSharp、PDFLibNet、Amyuni、asppdf、PDFTechLibなど]のような多くのライブラリをチェックしました。2つのライブラリを見つけました。この操作を行うことができます

  1. amyuniそのコードは単純ですが、位置を変更した後、別の問題が発生しました:図の色が変更されました、
  2. 他のライブラリはfoxitsoftwareであり、これは私がそれを行った方法のサンプルコードです。

    public static void Modify(string pdfFile)
    {
        IntPtr pdf_doc = IntPtr.Zero;
        IntPtr pdf_page = IntPtr.Zero;
        TextInfo TxtInfo = null;
        ObjectInfo ObjInfo = null;
        ArrBuf = new ArrayList();
        FPDFView.FPDF_InitLibrary(System.Diagnostics.Process.GetCurrentProcess().Handle);
        FPDFView.FPDF_UnlockDLL("xxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        pdf_doc = FPDFLIB.FPDFView.FPDF_LoadDocument(pdfFile, "");
        pdf_page = FPDFView.FPDF_LoadPage(pdf_doc, 0);
    
        IntPtr Page_Obj = FPDFEditBase.FPDFPage_GetObject(pdf_page, 0);
    
    
        FPDFEditBase.FPDFPageObj_Transform(Page_Obj, 1, 0,0, 1, 0, -40);
    
        ObjInfo = new ObjectInfo(pdf_doc, pdf_page, -1);
        ObjInfo.Delete(-1);
    
    
        FPDFLIB.FPDFEditBase.FPDF_FILEWRITE pFileWriter = new FPDFLIB.FPDFEditBase.FPDF_FILEWRITE();
        pFileWriter.wb = new FPDFEditBase.WriteBlock(MyDelegateFunc);
        //FPDFEditBase.FPDF_SaveDocument(pdf_doc, ref pFileWriter, 0, null, 0, null, 0, 0);
        bool flag = FPDFEditBase.FPDF_SaveDocument(pdf_doc, ref pFileWriter, 0, null, 0, null, 0, 0);
        if (flag == false)
            return;
        FileStream fs = new FileStream(pdfFile, FileMode.Create, FileAccess.Write);
        object[] myArr = ArrBuf.ToArray();
        for (int i = 0; i < myArr.Length; i++)
        {
            byte[] mybyte = (byte[])myArr[i];
            fs.Write(mybyte, 0, mybyte.Length);
        }
    
        fs.Close();
        fs.Dispose();
    
        FPDFLIB.FPDFView.FPDF_CloseDocument(pdf_doc);
    
    }
    static ArrayList ArrBuf = new ArrayList();
    
    public static int MyDelegateFunc(ref FPDFEditBase.FPDF_FILEWRITE pThis, IntPtr pData, UInt32 size)
    {
    
        byte[] byteData = new byte[size];
    
        System.Runtime.InteropServices.Marshal.Copy(pData, byteData, 0, (int)size);
        ArrBuf.Add(byteData);
    
        return 1;
    }
    

これが同じ問題を抱えている他の人にも役立つことを願っています。

于 2013-01-01T08:18:33.143 に答える
0

iTextSharp などの .NET 専用の API を使用して、pdf ファイルを再編集できると思います。

于 2012-12-31T13:37:11.870 に答える