Use LeadTools to write QR Bar Code to PDF file. But the quality of output PDF is look very bad

636 views Asked by At

The only thing I want from LeadTools is to be able to read/write QR bar code to pdf file. Here are the method that I created to write bar code to pdf:

private void WriteBarcodeToPDF(string ServerPath_imageFile, string value, bool topLeft = true) { // Create the barcode data QRBarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as 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);
        }
    }
}

Here are my issues:

  1. The value that I want to store in the bar code are just a number with 10-12 digits. That's it. I heard that there is QR Barcode 21x21 that has high ECC rate. Would you please fix my method so that it'll produce a bar code that meet my need (10-12 digits number) and has highest recovery rate (ECC)?

  2. The output pdf is having very bad quality, not only on the page that I put the bar code on, but every page in the pdf file has its text be degraded dramatically as well, I don't think that it is supposed to be like this. There gotta be something wrong in my method. Would you please fix it?

Thanks ALL.

1

There are 1 answers

0
LEADTOOLS Support On

About determining which Barcode that you need to use, read the following page that lists the amount of data that you can store in different QR barcodes: http://www.leadtools.com/sdk/barcode/qr-chart.htm

You can select the size by setting the SymbolModel property to "QRBarcodeSymbolModel.Model2Version1" instead of "QRBarcodeSymbolModel.Model2AutoSize". However, if you keep it set to AutoSize, the toolkit will automatically optimize the barcode size.

About the bad quality, the issue might be caused by the loading resolution of the source PDF. Try to increase the loading resolution to 300 DPI or higher. You can achieve that by setting both the XResolution and YResolution properties of the CodecsRasterizeDocumentLoadOptions class to the desired value.

See the following link: http://www.leadtools.com/help/leadtools/v18/dh/co/leadtools.codecs~leadtools.codecs.codecsrasterizedocumentloadoptions.html