Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - Convert RTF to PDF
  FAQ FAQ  Forum Search   Register Register  Login Login

Convert RTF to PDF

 Post Reply Post Reply
Author
Message
DELBEKE View Drop Down
Debenu Quick PDF Library Expert
Debenu Quick PDF Library Expert
Avatar

Joined: 31 Oct 05
Location: France
Status: Offline
Points: 151
Post Options Post Options   Thanks (0) Thanks(0)   Quote DELBEKE Quote  Post ReplyReply Direct Link To This Post Topic: Convert RTF to PDF
    Posted: 05 Nov 09 at 10:42AM
Here is a sample code writen with VB6 to transform an RTF file into a Pdf file, using the new functions GetCanvasDc & LoadFromCanvasDc
 
Option Explicit
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Private Type CharRange
     cpMin As Long     ' First character of range (0 for start of doc)
     cpMax As Long     ' Last character of range (-1 for end of doc)
End Type
Private Type FormatRange
     hDc As Long       ' Actual DC to draw on
     hdcTarget As Long ' Target DC for determining text formatting
     rc As RECT        ' Region of the DC to draw to (in twips)
     RcPage As RECT    ' Region of the entire DC (page size) (in twips)
     chrg As CharRange ' Range of text to draw (see above declaration)
End Type
Private Const WM_USER As Long = &H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Dim Doc As New QuickPDFAX0717.PDFLibrary
Private Sub Form_Load()
  Doc.UnlockKey "j53g77ru93q3ds9kw7ru59b8y" 'trial key
  'Size RichTextBox1 to A4 format
  RichTextBox1.Move 0, 0, ScaleX(210, vbMillimeters, vbTwips), ScaleY(297, vbMillimeters, vbTwips)
  'load some test file
  RichTextBox1.LoadFile App.Path & "\Test.rtf"
End Sub
Private Sub Command1_Click()
  Dim Dc As Long
  Dim PageNumber As Long
  Dim LastChar As Long
  Dim DocId As Long
  PageNumber = 1
  LastChar = 0
  Do
    'get a virtual device context size at A4
    Dc = Doc.GetCanvasDC(ScaleX(210, vbMillimeters, vbPixels), ScaleY(297, vbMillimeters, vbPixels))
    'print the rtfbox
    LastChar = ImprimeRtfBox(Dc, RichTextBox1, LastChar)
    'generate a new document
    Doc.LoadFromCanvasDc 96, 0
    DocId = Doc.SelectedDocument
    'save it to file
    Doc.SaveToFile App.Path & "\Test" & CStr(PageNumber) & ".pdf"
    'remove it from memory
    Doc.RemoveDocument DocId
    PageNumber = PageNumber + 1
  Loop While LastChar <> 0
  MsgBox "Done"
End Sub
Public Function ImprimeRtfBox(hDc As Long, rtfBox As RichTextBox, FirstChar As Long)
  Dim RcDrawTo As RECT
  Dim RcPage As RECT
  Dim Fr As FormatRange
  Dim NextCharPosition As Long
      RcPage.Left = 0
      RcPage.Right = rtfBox.Left + rtfBox.Width + 100
      RcPage.Top = 0
      RcPage.Bottom = rtfBox.Top + rtfBox.Height + 100
      RcDrawTo.Left = rtfBox.Left
      RcDrawTo.Top = rtfBox.Top
      RcDrawTo.Right = rtfBox.Left + rtfBox.Width
      RcDrawTo.Bottom = rtfBox.Top + rtfBox.Height
      Fr.hDc = hDc
      Fr.hdcTarget = hDc
      Fr.rc = RcDrawTo
      Fr.RcPage = RcPage
      Fr.chrg.cpMin = FirstChar
      Fr.chrg.cpMax = -1
      NextCharPosition = SendMessage(rtfBox.hWnd, EM_FORMATRANGE, True, Fr)
    If NextCharPosition < Len(rtfBox.text) Then
      ImprimeRtfBox = NextCharPosition
    Else
      ImprimeRtfBox = 0
    End If
End Function
 
Hope this may be usefull.


Edited by DELBEKE - 05 Nov 09 at 10:50AM
Back to Top
jurand View Drop Down
Beginner
Beginner


Joined: 23 May 12
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote jurand Quote  Post ReplyReply Direct Link To This Post Posted: 24 May 12 at 9:41AM
Helo, thanx 4 example, but
May you axplain your idea, I'll try this on Delphi,
unfortunately I can't get this code idea
 
 
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 24 May 12 at 10:21PM
Hi!

You've seen that this post is long ago ...
I won't hope for a new delphi code ...
Try it yourself for a new sample for us here ;-)

Cheers and welcome here,
Ingo

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store