Print Page | Close Window

Vertical position after DrawMultiLineText

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1754
Printed Date: 22 Nov 24 at 7:13PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Vertical position after DrawMultiLineText
Posted By: FernandoV
Subject: Vertical position after DrawMultiLineText
Date Posted: 02 Mar 11 at 4:39PM
 
I am trying to accomplishthe following:
 
1.- Placing multilines text in a page. The number of lines is dynamic but for this sample i am using 100 lines.
2.- Place an image just below the last line of text
3.- Add pages automatically as needed to fit the text and image.
 
Please advise
 
Thank You
 
This is what i have so far:
 
************ Sample VB.Net **************
Private Sub Test()
 
Dim qp as New QuickPDFAX????/PDFLibrary
Dim iID as Integer = 0
dim i as Integer = 0
dim sLine as String = String.Empty
 
'This block will just fake multi lines tobe added to the page
For  i = 0 to 100
      sLine += sLine + "Line " + i.ToString + ControlChars.CrLf
Next i
 
qp.SetOrigin(1)
qp.AddStandardFont(8)
qp.SetTextSize(7)
qp.DrawMultiLineText(100, 10, ControlChars.CrLf, sText)
 
'Now i need to add an image below the text
qp.CompressImages(1)
iID = qp.AddImageFromFile("c\test.jpg", 0)
qp.SelectImage(iID)
 
Dm YY as Double = ????    'current Vertical Position,  what is the vertical postion?

qp.DrawscaleImage(200, YY, 0.5)
qp.SaveToFile("c:\test.pdf")
 
 
End Sub



Replies:
Posted By: edvoigt
Date Posted: 13 Oct 11 at 4:27PM
Here is a solution-idea in Delphi. But the intention should come clear.
We need Informations like how much lines and how high. Nothing more. Little bit more is to do, if the text should fit in a given width. This is shown.

The code:

var
  QP: TQuickPDF;
  s: string;
  n: integer;
  hb, h, sizey: double;
begin
  QP := TQuickPDF.Create;
  QP.UnlockKey('your key');
  QP.SetOrigin(1);                // topleft
  QP.SetMeasurementUnits(1);      // millimeters
  QP.SetPageDimensions(210, 297); // DIN A4
  QP.AddStandardFont(8);
  QP.SetTextSize(16);
  s := 'This is the Text, which will be wrapped. Therefore we have to find out,'
      +' how much lines are there after wrapping. Then we calc the y-size of a '
      +'textbox.'+#13#10
      +'Here is a new line starting. We may see how high is a line and so we '
      +'find out what we need to know. Now you are able to count how much lines '
      +'fill the place on the page. So build new pages for the remainig lines '
      +'and figure out wether is there enough space for your image or not.'
      +#13#10+#13#10
      +'It is better to use the GetWrappedtext-function to split the text into'
      +' portions of lines depending on the y-size. It makes a little more work.';
  n := QP.GetWrappedTextLineCount(160, s);
  h := QP.GetTextHeight;
  hb := QP.GetTextBound(2);  // height over baseline because baseline is textstart
  sizey := n*h;              // the full text
  QP.DrawWrappedText(25.0, 15.0+hb, 160, s);
  QP.DrawBox(25.0, 15.0, 160.0, sizey, 0);  // show the needed space as box

I hope it helps,

Werner





Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk