HTML to RTF Lib
Posted: Fri Apr 28, 2023 8:23 am
Hello,
I found a free DLL to convert HTML to RTF (https://sautinsoft.com/products/convert ... to-rtf.php). The conversion just needs one API call, sample code (C) is included in the download package.
I was able to translate to PB and call the DLL: conversion of the file works, but the given parameters (as struct) are obviously ignored. When compiling the C source, all works well. Probably I've doing somwething wrong with converting the struct to PB, here is my code (PB 32bit):
Thank you for any hints... I'm using PB 6.01 32bit
I found a free DLL to convert HTML to RTF (https://sautinsoft.com/products/convert ... to-rtf.php). The conversion just needs one API call, sample code (C) is included in the download package.
I was able to translate to PB and call the DLL: conversion of the file works, but the given parameters (as struct) are obviously ignored. When compiling the C source, all works well. Probably I've doing somwething wrong with converting the struct to PB, here is my code (PB 32bit):
Code: Select all
;-> relevant C-code
; struct ConvertSettings
; {
; int PreserveTables; //1 - preserve tables, 0 - transfer to text
; int PreserveImages; //1 - preserve images, 0 - skip
; int PreserveHyperlinks; //1 - preserve hyperlinks, 0 - skip
; int PreserveFontFace; //1 - preserve font faces as in HTML, 0 - all font faces will be as in 'FontFace'
; int PreserveFontSize; //1 - preserve font sizes as in HTML, 0 - all font sizes will be as in 'FontSize'
; int PreserveFontColor; //1 - preserve font colors as in HTML, 0 - black font color
; int PreserveBackgroundColor; //1 - preserve bacground colors as in HTML, 0 - skip
; int PreserveAlignment; //1 - preserve alignment as in HTML, 0 - all text will have align as in 'PageAlignment'
; int PreserveTableWidth; //1 - preserve width of columns
; int PreserveNestedTables; //1 - preserve nested tables, 0 - translate nested tables to plain tables
; int PageMarginLeft; //page margin left, mm. For example 10
; int PageMarginRight; //page margin right, mm. For example 10
; int PageMarginTop; //page margin top, mm. For example 10
; int PageMarginBottom; //page margin bottom, mm. For example 10
; int BorderVisibility; //table borders: 1 - visible borders, 0 - hidden borders, 2 - as in HTML
; int PageOrientation; //page orientation: 0 - Portrait, 1 - Landscape
; int PageSize; //page size: 0 - A4, 1 - A3, 2 - A5, 3 - B5, 4 - Letter, 5 - Legal, 6 - Executive, 7 - Monarh
; int FontFace; //default font face: Arial - 0, Times New Roman - 1, Verdana - 2, Helvetica - 3, Courier - 4, Courier New - 5, Times - 6, Georgia - 7, MS Sans Serif - 8,
; //Futura - 9, Arial Narrow - 10, Garamond - 11, Impact - 12, Lucida Console - 13, Tahoma - 14, Inform - 15, Symbol - 16, WingDings - 17, Traditional Arabic - 18
; int FontSize; //default font size, any value from 6 to 72
; int PageAlignment; //page alignment: 0 - left, 1 - center, 2 - right, 3 - justify
; int RtfLanguage; //RTF language: English - 1033, Albanian - 1052, Belgian - 2067, Bulgarian - 1026, Hungarian - 1038, Danish - 1030, Spanish - 3082, Latvian - 1062, Lithuanian - 1063,
; //German - 1031, Netherlands - 1043, Norwegian - 2068, Portuguese - 2070, Romanian - 1048, Russian - 1049, Ukrainian - 1058, Finnish - 1035, French - 1036,
; //Czech - 1029, Swedish - 1053, Arabic - 1053, Turkish - 1055, Japanese - 932, SimplifiedChinese - 936, TraditionalChinese - 950, Korean - 949, Thai = 874
; int Encoding; //AutoSelect - 0, ISO-8859-1 - 1, ISO-8859-5 - 2, KOI8-R - 3, Windows-1251 - 4, UTF-8 - 5, Windows-1254 - 6, Windows-1256 - 7,
; //Windows-1250 - 8, Windows-1252 - 9, Windows-1253 - 10, Windows-1255 - 11, Windows-1257 - 12, Windows-1258 - 13
; int OutputTextFormat; //Output Format: Rtf - 0, Text - 1, Doc - 2 (only file with .doc extension)
; int PreservePageBreaks; //1 - preserve page-breaks
; int ImageCompatible; //type of produced images: Word - 0, WordPad - 1
; int PageNumbers; //page numbers: 0 - disable, 1 - numbers from first page, 2 - from second page
; char PageHeader[150]; //page header, any string
; char PageFooter[150]; //page footer, any string
; char HtmlPath[650]; //html path for method 'htmltortf_string', will be used for find images (now is not used)
; int PageNumbersAlignV; //page numbers vertical align: Top - 4, Bottom - 5
; int PageNumbersAlignH; //page numbers horizontal align: 0 - left, 1 - center, 2 - right, 3 - justify
; int PreserveHR; //1 - preseve <hr>, 0 - skip
; int RtfParts; //0 - rtf completely, 1 - only rtf body (to insert inside another rtf files)
; int CreateTraceFile; //1 - the component will create trace file, it helps to see how converting goes and shows errors
; char TraceFilePath[650]; //specifies path for trace file, for example "c:\\Trace.txt"
; int TableCellPadding; //specifies table cell padding in pixels, any value from 0 to 10
; int PreserveHttpImages; //1- download http images, 0 - skip them
; } ;
;
; //SET PARAMETERS
; struct ConvertSettings cs;
;
; cs.BorderVisibility = SameAsOriginalHtml;
; cs.Encoding = 0 ;
; cs.FontFace = 0 ;
; cs.FontSize = 9 ;
; strcpy(cs.HtmlPath,"") ;
; cs.ImageCompatible = 0 ;
; cs.OutputTextFormat = Rtf ;
; cs.PageAlignment = 0 ;
; strcpy(cs.PageHeader,"") ;
; strcpy(cs.PageFooter,"") ;
; cs.PageMarginBottom = 10 ;
; cs.PageMarginLeft = 15 ;
; cs.PageMarginRight = 15 ;
; cs.PageMarginTop = 15 ;
; cs.PageNumbers = 0 ;
; cs.PageNumbersAlignH = 1 ;
; cs.PageNumbersAlignV = 5 ;
; cs.PageOrientation = 0 ;
; cs.PageSize = 4 ;
; cs.PreserveAlignment = true ;
; cs.PreserveBackgroundColor = true ;
; cs.PreserveFontColor = true ;
; cs.PreserveFontFace = true ;
; cs.PreserveFontSize = true ;
; cs.PreserveHR = 0 ;
; cs.PreserveHyperlinks = true ;
; cs.PreserveNestedTables = true ;
; cs.PreservePageBreaks = true ;
; cs.PreserveTables = true ;
; cs.PreserveTableWidth = true ;
; cs.RtfLanguage = 1033 ;
; cs.RtfParts = 0 ;
; cs.PreserveImages = 1 ;
; cs.TableCellPadding = 0 ;
; cs.PreserveHttpImages = 1 ;
;
; //CONVERT
; retValue=htmltortf_file((char*)HtmlFile.c_str(),(char*)RtfFile.c_str(),cs);
Structure ConvertSettings Align #PB_Structure_AlignC
PreserveTables.i ;keep tables/transform To text
PreserveImages.i ;keep images
PreserveHyperlinks.i ;keep hyperlinks
PreserveFontFace.i ;keep font
PreserveFontSize.i ;keep font sizes
PreserveFontColor.i ;keep background colors
PreserveBackgroundColor.i ;keep background colors
PreserveAlignment.i ;keep alignment
PreserveTableWidth.i ;keep width of table's columns
PreserveNestedTables.i ;keep nested tables/ trasform
PageMarginLeft.i ;set left page margin
PageMarginRight.i ;set right page margin
PageMarginTop.i ;set top page margin
PageMarginBottom.i ;set bottom page margin
BorderVisibility.i ;specify table borders visibility
PageOrientation.i ;set portrait Or landscape page
PageSize.i ;specify page size (Letter, A4 ...)
FontFace.i ;set Default font
FontSize.i ;set Default font size
PageAlignment.i ;set Default text alignment
RtfLanguage.i ;specify RTf spelling language
Encoding.i ;Select encoding
OutputTextFormat.i ;output file format RTF Or Text
PreservePageBreaks.i ;keep page breaks
ImageCompatible.i ;image type (WordPad Or Word)
PageNumbers.i ;specify page numbers
sPageHeader.a[150] ;header
sPageFooter.a[150] ;footer
sHtmlPath.a[650] ;path
PageNumbersAlignV.i ;page numbers vertical alignment
PageNumbersAlignH.i ;page numbers horiz alignment
PreserveHR.i ;keep horiz rules <hr>
RtfParts.i ;completely rtf file Or only rtf body
CreateTraceFile.i ;creates trace(Debug) file
sTraceFilePath.a[650] ;trace file path
TableCellPadding.i ;set Default cell padding in pix
PreserveHttpImages.i ;set Default cell padding in pix
EndStructure
PrototypeC htmltortf_file(ssourcefile.p-ascii,sdestfile.p-ascii,flag)
PrototypeC flushlist()
Global htmltortf_file.htmltortf_file
Global flushlist.flushlist
Procedure.i LoadDLL()
Protected hDLL.i
hDLL = OpenLibrary(#PB_Any, "htmltortf_sautinsoft.dll")
If hDLL <> 0
htmltortf_file = GetFunction(hDLL, "htmltortf_file")
flushlist = GetFunction(hDLL, "flushlist")
ProcedureReturn hDLL
EndIf
ProcedureReturn #False
EndProcedure
iDLL=LoadDLL()
If IsLibrary(idll)
sheader$="Test"
Define cs.ConvertSettings
;cs\sHtmlPath=Space(650)
;cs\sPageHeader=@sheader$
;cs\sPageFooter=Space(150)
cs\PreserveTables=1
cs\PreserveImages=1
cs\PreserveFontSize=1
cs\PreserveTableWidth=1
cs\PageSize=0
cs\RtfLanguage=1031
cs\ImageCompatible=0
cs\PreserveImages=1
cs\PreserveHttpImages=1
cs\PreservePageBreaks=1
cs\PreserveHR=1
cs\PageMarginBottom=20
cs\PageMarginLeft=20
cs\PageMargintop=20
cs\PageMarginright=20
cs\PageOrientation = 0
;*cs\sPageHeader=@sheader$
cs\CreateTraceFile=1
ssource$="result.htm"
sdest$="result.rtf"
DeleteFile(sdest$)
result=htmltortf_file(ssource$,sdest$,cs) ;- Conversion works and result.rtf is generated, but the parameter in cs are ignored
RunProgram(sdest$)
Debug result
flushlist();
CloseLibrary(idll)
EndIf