DrawToDevice

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

DrawToDevice

Post by jeffp »

I'm looking to create a TBitmap from the PDF page using the DrawToDevice call. I've got most of it working but my issue is that IPXC_Page gets drawn to the upper left corner of the defined TBitmap below. I always consult the help before bothering you, but the help was a bit a sparce on this one so I did some guessing on how to set some of the parameters. It seems I'm missing something that will draw the device on the entire defined TBitmap size below. I ensure that the size of the TBitmap in Pixels has the same proportions as the page dimensions in Points.

Can you spot what I'm missing?

Code: Select all

procedure BuildPageBitmap(APage: IPXC_Page; var B: TBitmap; ASize: Integer);
var
  AWidth, AHeight: Double;
  W, H, ADPI: Integer;
  ARect: tagRECT;
  AMatrix: PXC_Matrix;
  AFlags: Integer;
  ARenderParams: IPXC_PageRenderParams;
  AOCContext: IPXC_OCContext;
begin
  ADPI := 300;

  if (B.PixelFormat = pfDevice) then B.PixelFormat := pf24bit;

  //Get Page dimensions in Points
  APage.GetDimension(AWidth, AHeight);

  //Make Sure the Image is not Too Big
  if (AHeight > AWidth) then
  begin
    if (P2X(AHeight, 100) > 4400) or (P2X(AWidth, 100) > 3400) then ADPI := 100;
  end else
  begin
    if (P2X(AWidth, 100) > 4400) or (P2X(AHeight, 100) > 3400) then ADPI := 100;
  end;

  //Convert to Pixes
  ADPI := Max(100, ADPI);
  W := Round(P2X(AWidth, ADPI));
  H := Round(P2X(AHeight, ADPI));

  if (ASize <= 0) then ASize := Max(H, W);

  if (H > W) then
  begin
    W := Ceil(ASize * (W / H));
    H := ASize;
  end else
  begin
    H := Ceil(ASize * (H / W));
    W := ASize;
  end;

  with ARect do
  begin
    Left := 0;
    Top := 0;
    Right := Left + W;
    Bottom := Top + H;
  end;

  B.SetSize(W, H);

  APage.GetMatrix(PBox_MediaBox, AMatrix); //Is PBox_MediaBox correct here? I tried others but didn't seem to make a difference.
  AFlags := DDF_AsVector;
  ARenderParams := nil;
  AOCContext := nil;

  APage.DrawToDevice(B.Canvas.Handle, ARect, AMatrix, AFlags, ARenderParams, AOCContext, nil);
end;

Thanks.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: DrawToDevice

Post by Sasha - Tracker Dev Team »

Hello Jeff,

There's a problem with the correct matrix that you should path to the DrawToDevice method. Please tell me more precisely what do you want - fit or stretch the page in the given image rectangle?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToDevice

Post by jeffp »

I want the PDF page to fill the entire rectangle, so I guess that means stretch. But since my defined rectangle has the same proportions as the PDF page width/height, wouldn't fit and stretch be the same?

I'm also open to using DrawToIXCPage if you feel that is a better approach, but would need a little guidance on how to set it up.

Also, I see that there are some Operations with the IPXV_Inst that do similar things. However, this would force me to open the PDF via the IPXV_Control and it wouldn't allow using this call in an independent thread. Correct? I'm am tending to shy away from using IPXV_Inst and use IPXC_Inst calls instead since many of my routines will be in multiple threads. Is this correct thinking? And I assume that the Operations in IPXV_Inst actuall make calls into IPXC_Inst anyway??

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: DrawToDevice

Post by Sasha - Tracker Dev Team »

Hello Jeff,

We've updated the Delphi sample with working code that you require.
Please check it here:
https://github.com/tracker-software/PDFEditSDK-Delphi
What was updated required for your problem:
https://github.com/tracker-software/PDF ... s#L97-L110

HTH,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToDevice

Post by jeffp »

I'm now needed to use DrawToIXCPage. I'm following your lead on the DrawToDevice example, but my image keeps coming out blank. Could you give me an example of how I can convert a PDF page to a IIXC_Page?

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: DrawToDevice

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Where exactly are you experiencing a problem? Our sample should do what you need. If you can, please describe why do you need to use DrawToIXCPage. For now, I can give you a code snippet on how to use it, though the precise usage may differ because I'll need a better description of the problem:

Code: Select all

	uint Pt2Px(double nPoint, double nDPI)
	{
		return (uint)((nPoint / 72.0) * nDPI + 0.5);
	}

	//Creating empty dest IIXC_Page including DPI
	PDFXEdit.IIXC_Page iDestPage = iInst.Page_CreateEmpty(Pt2Px(nW, nDPI), Pt2Px(nH, nDPI), PDFXEdit.IXC_PageFormat.PageFormat_8RGB, 0x0000FF);

	//Creating destination image rect
	PDFXEdit.tagRECT destRect;
	destRect.left = 0;
	destRect.bottom = 0;
	destRect.right = (int)iDestPage.Width;
	destRect.top = (int)iDestPage.Height;
	//Getting page matrix
	PDFXEdit.PXC_Matrix srcPageMatrix = srcPage.GetMatrix(PDFXEdit.PXC_BoxType.PBox_PageBox);
	//Getting source page Page Box without rotation
	PDFXEdit.PXC_Rect srcRect = srcPage.get_Box(PDFXEdit.PXC_BoxType.PBox_PageBox);
	//Getting visual source Page Box by transforming it through matrix
	TransformRect(srcPageMatrix, ref srcRect);
	//Filling destination iPage with the image
	srcPage.DrawToIXCPage(iDestPage, ref destRect, ref srcPageMatrix);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply