2013-08-18 84 views
1

我想從LeadTools中唯一能夠讀/寫QR條形碼爲pdf文件。下面是我創建寫條形碼爲pdf的方法:使用LeadTools將QR條碼寫入PDF文件。但輸出PDF的質量看起來非常糟糕

私人無效WriteBarcodeToPDF(串ServerPath_imageFile,字符串值,布爾左上=真){ //創建條形碼數據 QRBarcodeData條形碼= BarcodeData.CreateDefaultBarcodeData( BarcodeSymbology.QR)作爲QRBarcodeData; BarcodeEngine engine = new BarcodeEngine();

using (RasterCodecs codecs = new RasterCodecs()) 
    { 
     using (RasterImage image = codecs.Load(ServerPath_imageFile)) 
     { 
      // Save the image 
      barcode.SymbolModel = QRBarcodeSymbolModel.Model2AutoSize; 
      barcode.Value  = value; 

      // We will use the alignment to position the barcodes, so use all of the image 
      barcode.Bounds  = new LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel); 

      // Set the write options 
      QRBarcodeWriteOptions options = new QRBarcodeWriteOptions(); 

      if (topLeft) 
      { 
       options.HorizontalAlignment = BarcodeAlignment.Near; 
       options.VerticalAlignment = BarcodeAlignment.Near; 
      } 
      else 
      { 
       options.HorizontalAlignment = BarcodeAlignment.Far; 
       options.VerticalAlignment = BarcodeAlignment.Far; 
      } 

      //Options 
      options.GroupNumber = 0; 
      options.GroupTotal = 0; 
      options.XModule  = 30; //(Value allowed: 1 - 100) 
      options.ECCLevel = QRBarcodeECCLevel.LevelH; 

      // Write it 
      engine.Writer.WriteBarcode(image, barcode, options); 

      //Save As new Image. 
      codecs.Save(image, ServerPath_imageFile, RasterImageFormat.RasPdf, 1); 
     } 
    } 
} 

這裏是我的問題:

  1. ,我想在條碼存儲的價值只是一個10-12位數字。而已。我聽說有QR碼21x21具有很高的ECC碼率。請您修理我的方法,以便它能生成滿足我需求(10-12位數字)並具有最高恢復率(ECC)的條形碼?

  2. 輸出pdf質量非常差,不僅在我放條形碼的頁面上,而且PDF文件中的每個頁面都有其文本也會顯着降低,我不認爲它應該是這樣的。我的方法有問題。你能解決它嗎?

謝謝ALL。

回答

1

關於確定你需要使用的條形碼,請閱讀以下頁面,其中列出的數據,你可以在不同的QR條碼存儲量: http://www.leadtools.com/sdk/barcode/qr-chart.htm

您可以通過SymbolModel屬性設置爲選擇尺寸「QRBarcodeSymbolModel.Model2Version1」而不是「QRBarcodeSymbolModel.Model2AutoSize」。但是,如果將其設置爲AutoSize,則工具包將自動優化條碼大小。

關於質量不好,該問題可能是由源PDF的加載分辨率造成的。嘗試將加載分辨率提高到300 DPI或更高。您可以通過將CodecsRasterizeDocumentLoadOptions類的XResolution和YResolution屬性設置爲所需的值來實現此目的。

看到下面的鏈接: http://www.leadtools.com/help/leadtools/v18/dh/co/leadtools.codecs~leadtools.codecs.codecsrasterizedocumentloadoptions.html