Two Pilots™    Home  |  Navigation  |  Site Map  |  Products  |  Download  |  Prices  |  For Partners  |  Support


All forums · Statistics · Search ·

Two Pilots forum / For software developers / Target size of hdc?
Author Message
Anonymous
# Posted: 27 Dec 2005 18:13


Hi,

I want to create a pdf, where part of it is coming from a RichTextBox (Visual Basic). I've found a solution (see below) so the richtextbox sends its 'output' to a hDC. But it needs to know the target-area. I've tried several things, but can't find the correct formula to calculate xmax and ymax (==size of hdc). With .PDFPage_Width and Height, it's about factor 18 too small... (default resolution)
Any help?

===8<----------------------------------------------------------
Private Sub start_Click()
Dim myhdc As Long

Set pdf = CreateObject("PDFCreatorPilot2.piPDFDocument")
With pdf
.StartEngine "demo@demo", "demo"
.FileName = "HelloPDF_VB.pdf"
.BeginDoc
.PDFPage_Width = 18.28 * cm2i * .resolution ' 18.28cm, cm2i=1/2.54
.PDFPAGE_Height = 15.56 * cm2i * .resolution

myhdc = .hdc
PrintRTB2DC RichTextBox1, myhdc, .PDFPage_Width, .PDFPAGE_Height
.EndDoc
End With
Set pdf = Nothing
End Sub

Private Sub PrintRTB2DC(rch As RichTextBox, hdc As Long, xmax, ymax)
Dim format_range As FORMATRANGE
'
' Prepare the FORMATRANGE structure.
With format_range
.hdc = hdc
.target_hdc = hdc
With .entire_area
.Left = 0
.Right = xmax
.Top = 0
.Bottom = ymax
End With
With .target_area
.Left = 0
.Right = xmax
.Top = 0
.Bottom = ymax
End With
With .char_range
.char_before = 0
.char_after = -1
End With
End With
Call SendMessage(rch.hwnd, EM_FORMATRANGE, True, format_range)
End Sub
===8<----------------------------------------------------------

Anonymous
# Posted: 27 Dec 2005 18:27


PS Could it be, that I have to convert from pixels to twips? The original code, I took this trick from, used
.ScaleX(.ScaleWidth, vbPixels, vbTwips)
for xmax, but here, a PictureBox was used. RichTextbox has no .scalex, and me thinks pdf also not. I tried Screen.TwipsPerPixelX, but that's not the right one either :(

Thanks.
Steven

Stanislav
# Posted: 27 Dec 2005 18:37


Hello,

The default resolution for DC used by library is 96 dpi. So, for you
xmax should be 18.28 * cm2i * 96 = 691, ymax 15.56 * cm2i * 96 = 588

Thank you very much !

Best regards,
Stanislav
Two Pilots

Stanislav
# Posted: 27 Dec 2005 18:38


Dear Steven,

No, you don't need recalculate to twips. Pixels (or, to be more correct, points) are used.

Thank you very much !

Best regards,
Stanislav
Two Pilots

Anonymous
# Posted: 27 Dec 2005 19:44


Hi, Stanislav,

thanks for the quick answer. Unfortunately, it was not the correct answer :)
The following gave me a perfect target area:

===8<-------
Const TWIPS_PER_INCH = 1440
TwipsPerPix = TWIPS_PER_INCH / .Resolution
[...]
PrintRTB2DC RichTextBox1, myhdc, .pdfPage_Width * TwipsPerPix, .pdfPage_height * TwipsPerPix
===8<-------

Thanks anyway!

Cheers,
Steven

Anonymous
# Posted: 14 Feb 2006 20:27


Hi Steven,

you are obviously using VB6 or earlier. Does "myhdc = .hdc" really work? If so, please tell me, which version of PDF-Creator you are using. I need the same solution to deal with RTF-Text.

Thanks!

Hans-Gerd (from Germany)

 

 

Powered by miniBB 2.0 RC7 © 2001-2004 Page creation time (sec.): 0.014

 

Page top