WPCubed Product Support

PrintHDC Image quality

wpsupport

This is one way to use it. It creates file on the harddrive, so you need a temporary file name.

os := WorkPath.Text + 'page_x%d.' + FileFormat.Text;

s := 'test.pdf';

n := wpview_pdfMakeImageW(PWideChar(s), '',

PWideChar(WPViewPDF_LicName), PWideChar(WPViewPDF_LicKey), WPViewPDF_LicCode,

PWideChar(os),

0, 10000, 300);

n is the number of created files.

#4 ♥ 0
4.5k Views 2 users read 2 min

Julian,

I went with the wpview_pdfMakeImage function. Is there a good explanation of the "jpegres:Integer" parameter. I tried 100, thinking it was a percentage, and I had seen it in an example, but the image is about the same quality as before.

This in your Instruction pdf, but it's over my head:

jpegres: - low-word (0000XXXX): the resolution for the JPEG file (default = 72),

hi-word: various options:

The lower nibble of the higher word is used to select the color depth.

It may may have this values:

1 : 1 bit monochrome dithered

2 : 1 bit monochrome not dithered

3 : 8 bit color

4 : 8 bit gray

otherwise: 24 bit color

The high byte of the high word is used to select the JPEG compression level

Some example of low medium high would help me.

Thanks.

#3 ♥ 0
wpsupport

Since you work with bitmaps I strongly recommend to use the makeimage api and not printhdc. You can specify the resolution for the image and so avoid degrading quality.

#2 ♥ 0

Julian,

I wrote a pass-through function in ReportBuilder to render each page of a PDF and display in a ppImage. However the resulting image seems to lose some quality compared to what your demo app does with the image. And this is the raw image saved to file (2nd to last line). Any tips on getting 100% image quality?

Thanks.

        lBitmap := TBitmap.Create;
        lBitmap.Width:=816;//408;//817;
        lBitmap.Height:=1056;//523;//1057;
        //lBitmap.
        lCanvas := lBitmap.Canvas;

        //How do I load the pdf from the stream?
        zTempfilename := ExtractFilePath(ParamStr(0))+'tempPDF.pdf';
        zStream.SaveToFile(zTempfilename);
        wpview_pdfWorkbenchLoad(workbench, PWideChar(zTempfilename), 0, 0);

        wpview_pdfWorkbenchCommand( workbench, COMPDF_PrintHDCSetXRes, Floor(-lBitmap.Width), '', nil );
        wpview_pdfWorkbenchCommand( workbench, COMPDF_PrintHDCSetYRes, Floor(-lBitmap.Height), '', nil );
        wpview_pdfWorkbenchCommand( workbench, COMPDF_PrintHDC_SelectPage, lsPDFPageNo-1, '', nil );//Select the page
        wpview_pdfWorkbenchCommand( workbench, COMPDF_UseGDIPainter, -1, '', nil);//use GDI
        wpview_pdfWorkbenchCommand( workbench, COMPDF_PrintUseBitmaps, 1, '', nil);//2020-01-03 Dan.  Improve quality?
        lCanvas.Lock;
        try
        wpview_pdfWorkbenchCommand( workbench, COMPDF_PrintHDC_SelectedPage, 0, '', Pointer( lCanvas.Handle  ));
        finally
          lCanvas.UnLock;
        end;
        //For Debugging lBitmap.SaveToFile(ExtractFilePath(ParamStr(0))+'PDF_Page_'+IntToStr(lsPDFPageNo)+'_.emf');
        lsImage.Picture.Bitmap.Assign(lBitmap);
#1 ♥ 0