pxvrpf_UseVectorRenderer Flag in DrawPageToDC

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

jeffp
User
Posts: 923
Joined: Wed Sep 30, 2009 6:53 pm

pxvrpf_UseVectorRenderer Flag in DrawPageToDC

Post by jeffp »

Consider the relevant code below.

I'm trying to create a TBitmap from DrawPageToDC and then create a new PDF Page using the TBitmap. However, when I use the pxvrpf_UseVectorRenderer Flag (I want to use it to speed up the rendering process), the resulting PDF page does not show the image. It's as if the image cannot be placed on the page when this flag is used.

If I EXCLUDE the pxvrpf_UseVectorRenderer Flag, then the image and PDF page get created correctly.

Code: Select all

...

AParams.WholePageRect := @AWholePage;
AParams.DrawRect := nil;
AParams.RenderTarget := pxvrm_Exporting;
AParams.Flags := pxvrpf_UseVectorRenderer;

hr := PXCV_DrawPageToDC(hDoc, APage - 1, B.Handle, @AParams);

...

PXC_AddImageFromHBITMAP(hDoc, B.Handle, 0, @hImg);

PXC_PlaceImage(hPage, hImg, 0, AHeight, AWidth, AHeight);

User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: pxvrpf_UseVectorRenderer Flag in DrawPageToDC

Post by Lzcat - Tracker Supp »

Can you provide sample project illustrating this problem, please?
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
jeffp
User
Posts: 923
Joined: Wed Sep 30, 2009 6:53 pm

Re: pxvrpf_UseVectorRenderer Flag in DrawPageToDC

Post by jeffp »

Here it is. Just copy the procedure below in a Delphi Unit. I've also attached the PDF file that I start with.

Code: Select all

procedure VectorTest;
var
  hr: HRESULT;
  hDoc, hImg, hPage: Cardinal;
  B: TBitmap;
  ADir, APDFFile, ABmpFile, ATIFFile, ANewPDFFile, ARegKey, ADevCode: String;
  AWidth, AHeight: Double;
  H, W: Integer;
  AWholePage: TRect;
  AParams: PXV_CommonRenderParameters;
  bUseVector: Boolean;
begin
  //VECTOR RENDERING NOTE:
  //When bUseVector is True, ANewPDFFile results in a Blank PDF
  //When bUseVector is False, works fine.
  bUseVector := False;

  ARegKey := '<YOUR REG CODE>';
  ADevCode := '<YOUR DEV CODE>';

  ADir := 'F:\PROJECTS\Tracker Software\Distrib\';
  APDFFile := 'OCR.pdf';
  ABmpFile := 'BmpFile.bmp';
  ATIFFile := 'TIFFile.tif';
  ANewPDFFile := 'OCR_Result.pdf';

  B := TBitmap.Create;

  //STEP 1: OPEN PDF IN VIEWER
  hr := 0;
	hr := PXCV_Init(@hDoc, PChar(ARegKey), PChar(ADevCode));
  hr := PXCV_ReadDocumentW(hDoc, PWChar(WideString(ADir + APDFFile)), 0);

  //STEP 2: DRAW PAGE TO DC
  PXCV_GetPageDimensions(hDoc, 0, @AWidth, @AHeight); //Sizes are in Points
  W := Round((AWidth / 72) * 100 * 3); //Convert to Pixels
  H := Round((AHeight / 72) * 100 * 3); //Convert to Pixels

  with AWholePage do
  begin
    Left := 0;
    Top := 0;
    Right := Left + W;
    Bottom := Top + H;
  end;
  B.Width := W;
  B.Height := H;

  AParams.WholePageRect := @AWholePage;
  AParams.DrawRect := nil;
  AParams.RenderTarget := pxvrm_Exporting;
  if bUseVector then AParams.Flags := pxvrpf_UseVectorRenderer; //ISSUES HERE???

  hr := PXCV_DrawPageToDC(hDoc, 0, B.Canvas.Handle, @AParams);
  hr := PXCV_Delete(hDoc);
  hDoc := 0;

  //STEP 3: SAVE BMP TO FILE
  B.SaveToFile(ADir + ABmpFile);

  //STEP 4: CONVERT BMP To TIFF
  hImg := 0;
  IMG_Init(PChar(ARegKey), PChar(ADevCode));
  IMG_ImageCreateEmpty(hImg);
  IMG_PageCreateFromHBITMAP(B.Handle, 0, @hPage);
  hr := IMG_PageSetFormatLongParameter(hPage, IXC_FP_ID_FORMAT, IXC_FMT_TIFF_ID);
  hr := IMG_PageSetFormatLongParameter(hPage, IXC_FP_ID_ITYPE, IXC_ImageFormat_RGB_8);
  hr := IMG_ImageInsertPage(hImg, 0, hPage);
  hr := IMG_ImageSaveToFileA(hImg, PAnsiChar(ADir + ATIFFile), IXC_CreationDisposition_Overwrite);

  //STEP 5: INSERT BMP To NEW PDF FILE
  hr := PXC_NewDocument(@hDoc, PChar(ARegKey), PChar(ADevCode));
  AWidth := 8.5 * 72;
  AHeight := 11 * 72;
  PXC_AddPage(hDoc, AWidth, AHeight, @hPage);
  PXC_SetCompression(hDoc, True, False, ComprType_C_Deflate, 75, ComprType_I_Deflate, ComprType_M_Deflate);
  PXC_AddImageFromHBITMAP(hDoc, B.Handle, 0, @hImg);
  PXC_PlaceImage(hPage, hImg, 0, AHeight, AWidth, AHeight); //Note: seems to fail with a Vector BMP
  hr := PXC_WriteDocumentA(hDoc, PAnsiChar(ADir + ANewPDFFile));

  B.Free;
end;
You do not have the required permissions to view the files attached to this post.
jeffp
User
Posts: 923
Joined: Wed Sep 30, 2009 6:53 pm

Re: pxvrpf_UseVectorRenderer Flag in DrawPageToDC

Post by jeffp »

I think I discovered the problem. In the code I just posted, my TBitmap has a default PixelFormat of pfDevice.

If I set the PixelFormat to

B.PixelFormat := pf24bit;

then the vector rendering works just fine.

So what are the pros and cons of using pxvrpf_UseVectorRendering?
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: pxvrpf_UseVectorRenderer Flag in DrawPageToDC

Post by Lzcat - Tracker Supp »

We have two different renderers - Raster and Vector.
The Raster renderer rasterizes everything and than puts bitmap over DC. Vector renderer tries to draw curves, draw text as text or at least as curves, etc.

In the Viewer Raster rendering is used to display the PDF on screen, and Vector - is used for printing (if you have not set the "print as image" option).

Both of them produce slightly different results, and in most cases the Raster renderer gives better results (but when printing necessarily - also much larger, so the Vector renderer is almost always faster with almost the same and sometimes better results).

HTH.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.