2012-12-31 43 views
0

通過.net應用程序,我想通過移動第一行或第一個單詞的小空格來修改pdf文檔。更改或移動PDF文件中的文本位置

是否有任何庫可以幫助我以編程方式更改PDF文檔上的某些文本位置?

我想改變PDF文本對象的y位置,這個操作將完成很多文件,我不想使用任何中間過程,如轉換爲SVG或單詞,我想直接修改pdf文件。

我檢查了一些圖書館,如PdfSharp,iTextSharp,PDFLibNet,Amyuni,pdfclown,我沒有找到解決這個問題的方法。

+0

你需要提供更多的細節來讓我們回答你的問題。例如,你如何創建PDF,你使用iTextSharp?還可以考慮用您正在使用的語言標記問題,例如C#或VB.NET –

+1

歡迎來到StackOverflow。你可能想要更好地描述你在做什麼以及你被困在哪裏。您是否生成新的PDF文件?或者你想修改一個現有的?您是否使用特定的PDF庫? – Codo

+0

你說你想移動一個段落。 PDF不知道段落。因此,請準確描述您想要移動的PDF對象。 – mkl

回答

1

超過一個月的研究解決方案,以移動PDF文件上的文本對象,我已經檢查了許多庫[Docotic,pdfclown,iTextSharp,PdfSharp,PDFLibNet,Amyuni,asppdf,PDFTechLib等],我發現兩個庫可以做這件事操作

  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; 
    } 
    

我希望這將成爲其他誰得到了同樣的問題很有幫助。

-1

我認爲你可以使用特定的API(例如iTextSharp)重新編輯pdf文件。

+1

謝謝user1929959, iTextSharp不能改變y位置並保存到同一個文件中 –

+0

您想要使用某種方法。這個API包含了一些通用的功能,而不是某些特定的需求,所以在使用它之前你必須學習一些東西。另一種方法是嘗試將PDF轉換爲一個或多個圖像文件,然後嘗試操作這些圖像的各種屬性。 – user1929959