2009-09-18 77 views
1

使用TWAIN掃描儀進行即時通訊& gdiplus.dll。用c#掃描並保存爲PDF格式

我掃描的文件,並且可以保存像* .JPG圖像格式,* .BMP

但不允許保存爲PDF格式。顯示錯誤未知格式圖片。

這是代碼,


公共靜態布爾SaveDIBAs(字符串picname,IntPtr的bminfo,IntPtr的pixdat) {

 SaveFileDialog sd = new SaveFileDialog(); 
     sd.FileName = picname; 
     sd.Title = "Save bitmap as..."; 
     sd.Filter = "PDF (*.pdf)|*.pdf"; 
     sd.Filter = "Bitmap file (*.bmp)|*.bmp|TIFF file (*.tif)|*.tif|JPEG file (*.jpg)|*.jpg|PNG file (*.png)|*.png|PDF file (*.pdf)|*.pdf|All files (*.*)|*.*"; 

     sd.FilterIndex = 1; 
     if (sd.ShowDialog() == DialogResult.OK) 

      return false; 


     Guid clsid; 
     if (!GetCodecClsid(sd.FileName, out clsid)) 
     { 
      //MessageBox.Show("Unknown picture format for extension " + Path.GetExtension(sd.FileName), 
          "Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information); 
      return false; 
     } 

     IntPtr img = IntPtr.Zero; 
     int st = GdipCreateBitmapFromGdiDib(bminfo, pixdat, ref img); 
     if((st != 0) || (img == IntPtr.Zero)) 
      return false; 

     st = GdipSaveImageToFile(img, sd.FileName, ref clsid, IntPtr.Zero); 
     GdipDisposeImage(img); 
     return st == 0; 
     } 
      [DllImport("gdiplus.dll", ExactSpelling=true)] 
     internal static extern int GdipCreateBitmapFromGdiDib(IntPtr bminfo, IntPtr pixdat, ref IntPtr image); 

      [DllImport("gdiplus.dll", ExactSpelling=true, CharSet=CharSet.Unicode)] 
     internal static extern int GdipSaveImageToFile(IntPtr image, string filename, [In] ref Guid clsid, IntPtr encparams); 

      [DllImport("gdiplus.dll", ExactSpelling=true)] 
     internal static extern int GdipDisposeImage(IntPtr image); 
    } 

   ****The above code doesnt allow to save as in PDF format.**** 
+0

掃描什麼文件? – ceejayoz 2009-09-18 02:48:26

+0

'GdipSaveImageToFile'功能不支持PDF格式。 – 2009-09-18 06:15:37

回答

3

首先你需要使用TWAINWIA獲取圖像,然後一旦捕獲您需要使用類似abcPDF

1

將其轉換爲PDF格式的圖像不完全確定您在說什麼,但該庫:http://sourceforge.net/projects/pdflibrary/非常適合保存PDF。

對於掃描(從TWAIN掃描儀?)檢查出http://www.codeproject.com/KB/dotnet/twaindotnet.aspx我以前做過,而且它似乎工作得很好。

+0

我無法掃描圖像文件爲PDF ... Plz幫助我。 – nithi 2009-09-24 02:11:03

+0

您必須先通過TWAIN/WIA設備掃描它們。此時,大多數輸出​​到某種圖像,然後您可以使用pdflibrary保存它。沒有直接用於Scan-> PDF的C#庫,您必須結合其他兩件事情。 – Erich 2009-09-24 02:14:29

0

如果您使用的是GDI。直接打印到PDF打印機(我自己使用bullzip pdf,因爲它本身免費且具有無聲打印功能)

1

它不會保存爲PDF,因爲Microsoft的GDI庫不具備PDF功能,所以最好的方法是首先將臨時文件中的文件保存爲JPEG格式。然後使用iTextSharp庫或PDFSharp庫來創建PDF格式的PDF,您可以使用這兩個庫在JPG/Bitmap中嵌入任何類型的文件。

相關問題