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 > I need help - I can help
  New Posts New Posts RSS Feed - Create PDF from a text file
  FAQ FAQ  Forum Search   Register Register  Login Login

Create PDF from a text file

 Post Reply Post Reply
Author
Message
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Topic: Create PDF from a text file
    Posted: 10 Sep 14 at 7:08AM
I wonder how could you create a PDF file from an existing text file?
Back to Top
AndyD View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Apr 13
Location: UK
Status: Offline
Points: 54
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndyD Quote  Post ReplyReply Direct Link To This Post Posted: 10 Sep 14 at 10:37AM
If you are using VB you can load the text into memory and the draw this text onto a new PDF using QPL.
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 10 Sep 14 at 5:22PM
When I use "DrawText" it just create one long line only. It does not wrap around the page.

Edited by Ben - 10 Sep 14 at 5:23PM
Back to Top
AndyD View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Apr 13
Location: UK
Status: Offline
Points: 54
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndyD Quote  Post ReplyReply Direct Link To This Post Posted: 10 Sep 14 at 5:32PM
Use

QP.DrawWrappedText(400, 50, 200, "This text was drawn using the DrawWrappedText function. As you can see, the text automatically wraps when it exceeds the specified width.");

You specifiy the location and size of the bounding box, then the text automatically wraps within it.
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 10 Sep 14 at 6:14PM
Thanks AndyD for the neat function.

Ok the thing its wraps around the page is fixed, but the next problem is if the file has more than one page and this function will just display one page of info only and the rest is lost.

How could you overcome that?
Back to Top
AndyD View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Apr 13
Location: UK
Status: Offline
Points: 54
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndyD Quote  Post ReplyReply Direct Link To This Post Posted: 11 Sep 14 at 8:32AM
Ok firstly is the source a Word document, rtf or a .txt file?
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 11 Sep 14 at 5:47PM
The source is just plain text file.
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 14 at 7:54AM
interesting problem 
Honestly I was going to do something like that - but then I got other jobs to do. 

btw.
in 
Debenu Quick PDF Library 11.11 Dashboard (4.10)

there is a section "Conversion" 
and in it are two examples of "Image to PDF", "PDF to Image" 

It is a pity that there is no appropriate example to convert a multi-page text file to PDF file.

Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
AndyD View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Apr 13
Location: UK
Status: Offline
Points: 54
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndyD Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 14 at 11:42AM
Right, I've had a little play in VB6 and come up with the following. This routine will load a text file and split the content into an array of text strings based on the number of lines you need per page. This will be trial and error to determine the number based on text are size on the page, font ans font size etc.
 
Once you have run this routine you will just need to create a new PDF and add the required number of pages (PageCount Variable), drawing the wrapped text from the appropriate string for that page (PageText(PageCount)).
 
I haven't had time to test this all the way through but hopefully this will help you some way to sorting it out.
 
CODE:
 
Private Sub Command1_Click()
    Call TextSplit
End Sub
 
Private Sub TextSplit() ' This function splits the loaded text into an array of text strings based on the required number of lines per page
    Dim pos As Integer
    Dim entry() As String
    Dim LineCount As Integer
    Dim PageCount As Integer
    Dim PageText(1 To 999) As String
    Dim MaxLines As Single
   
        pos = 0
    LineCount = 0
    PageCount = 1
    MaxLines = 50 ' This will change depending on the font type and size etc
   
    entry = Split(Text2String("Textfile.txt"), vbCrLf, , vbTextCompare) ' replace Textfile.txt with your file and location
    Do While pos < UBound(entry)
        If LineCount = MaxLines Then
            PageCount = PageCount + 1
            LineCount = 0
        End If
        If Trim$(entry(pos)) <> "" Then
            PageText(PageCount) = PageText(PageCount) & vbCrLf & entry(pos)
        End If
        LineCount = LineCount + 1
        pos = pos + 1
    Loop
End Sub
 
Public Function Text2String(strPath As String) As String ' This loads the text file into memory allowing for line returns
    On Error GoTo ErrTrap
    Dim intFileNumber As Integer
    Dim entry() As String
   
    If Dir(strPath) = "" Then Exit Function
    intFileNumber = FreeFile
    Open strPath For Input As #intFileNumber
   
    Text2String = Input(LOF(intFileNumber), #intFileNumber)
    entry = Split(Text1.Text, vbCrLf, , vbTextCompare)
ErrTrap:
    Close #intFileNumber
End Function
 
 
Regards
 
Andy


Edited by AndyD - 12 Sep 14 at 11:43AM
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 14 at 12:41PM
I think it must be done with GetWrappedTextHeight and DrawWrappedText
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
AndyD View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Apr 13
Location: UK
Status: Offline
Points: 54
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndyD Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 14 at 12:45PM
GetWrappedTextHeight will give him the height of the text block yes but is this the number of lines it will contain or the actual block height in pixels?
 
If it's the pixel height then he will need to output a sample to physically see how many lines of text he can fit onto each page.
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 14 at 12:51PM
you must read TXT file to variable
split variable to array - split by NEW LINE (@CRLF)
now in loop check

Local $sTemp = ''
For $i = 1 to ubond($array) -1
      $sTemp &= $array[$i]
      $iHeight = GetWrappedTextHeight ($iA4Width , $sTemp)
      If $iHeight > $iA4Height Then .......
Next

something like this


Edited by mLipok - 12 Sep 14 at 12:55PM
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
AndyD View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Apr 13
Location: UK
Status: Offline
Points: 54
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndyD Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 14 at 12:54PM
Ok well hopefully between us we have helped him out Smile
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 14 at 12:57PM
I will check my concept in practice.
but not now.

Actually I have other project to maintain.

Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 14 at 3:01AM
I don't use VB so I could not apply what AndyD has suggested yet. But I follow mLipok suggestion and I could convert a text file into a PDF file even though it's not 100% like what I expected but it works.

Thanks both for the input.
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 14 at 7:24AM
Originally posted by Ben Ben wrote:

it's not 100% like what I expected but it works.

Whats going wrong ?
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 14 at 7:47AM
The page display is not with fixed size. Some pages have more text than the other, and some has shorter text.


Edited by Ben - 13 Sep 14 at 7:48AM
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 14 at 7:56AM
When you check that the line can not fit on the page, then you need this line, divided/split into words, and check word by word.

Edited by mLipok - 13 Sep 14 at 8:00AM
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 14 at 7:58AM
ps.
When you finish , it would be nice if you share your solution.
Then we can be able to further help / improvements
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 14 at 3:32PM
I use Quick Macros and here is my program. Feel free to make any suggestion to improve it.

    str s.getfile("$Documents$/Test File.txt")
    ARRAY(str) a=s
    int xPos = 50
    int startLine = 60
    int lineCount = 0
    int maxLines = 600
    int width = 520
    double height = 0
    QP.SetOrigin(1)
    int pid = QP.AddStandardFont(4)
    QP.SelectFont(pid)
    QP.SetTextSize(16)
    double standard_height=18.496  ;; this will change when selected font and font size change

    for int'i 0 a.len
        QP.DrawWrappedText(xPos, startLine, width, a[ i ])

        height = QP.GetWrappedTextHeight(width , a
[ i ])

        lineCount = (height / standard_height) * 20

        if(lineCount=0) lineCount=10

        startLine + lineCount

        if (startLine >= maxLines)
            QP.SelectPage(QP.NewPage())
            startLine = 60
            QP.SelectFont(pid)
            QP.SetTextSize(16)

    QP.SaveToFile(_s.expandpath("$Documents$/outfile.pdf"))


Edited by Ben - 13 Sep 14 at 3:46PM
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 14 Sep 14 at 10:18AM
here is my extended concept:

Func _QPDF_TXT_to_PDF(ByRef $oQP, $sText, $iLeftMargin = 20, $iRighMargin = 10, $iTopMargin = 10, $iBottomMargin = 10, $sTABtoSpace = 4)

; TODO $sTABtoSpace
$sText = StringReplace($sText, @TAB, Chr(160) & Chr(160) & Chr(160) & Chr(160) )

Local $sLineTemp = '', $sPageTxtTemp = ''
Local $iHeightTemp
Local $aTextSplited = StringSplit($sText, @CRLF, $STR_ENTIRESPLIT)
Local $iTextWidth = $__eQPDF_A4_WidthInMM - $iLeftMargin - $iRighMargin
Local $iTextHeight = $__eQPDF_A4_HeightInMM - $iTopMargin - $iBottomMargin
_ArrayDisplay($aTextSplited, '$aTextSplited')
$oQP.SetOrigin($__eQPDF_SORIGIN_TopLeft);
$oQP.SetMeasurementUnits($__eQPDF_MUNITS_Milimeters)
For $iLine = 1 To UBound($aTextSplited) - 1
$sLineTemp = $aTextSplited[$iLine]
$iHeightTemp = $oQP.GetWrappedTextHeight($iTextWidth, $sPageTxtTemp & @CRLF & $sLineTemp)
If _
($iHeightTemp > $iTextHeight) _
Or _
($iLine = UBound($aTextSplited) - 1) _
Then
$oQP.DrawWrappedText($iLeftMargin, $iTopMargin, $iTextWidth, $sPageTxtTemp)
If ($iLine <> UBound($aTextSplited) - 1) Then $oQP.NewPage()
$oQP.SetOrigin($__eQPDF_SORIGIN_TopLeft);
$oQP.SetMeasurementUnits($__eQPDF_MUNITS_Milimeters)
MsgBox(0, $iLine & '/' & UBound($aTextSplited) - 1, $sPageTxtTemp)
$sPageTxtTemp = $sLineTemp & @CRLF
Else
$sPageTxtTemp &= $sLineTemp & @CRLF
EndIf
Next

EndFunc   ;==>_QPDF_TXT_to_PDF

Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 14 at 7:10AM
I noticed that if the lines at the beginning are spaces, then the function DrawWrappedText removes trailing spaces from the line. 

Can anyone confirm my observations ?

Best regards,
mLipok

Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 14 at 7:26AM
Yes, I see that too.
Back to Top
AlexA_B View Drop Down
Beginner
Beginner


Joined: 08 Sep 14
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexA_B Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 14 at 2:50PM
I try to write it in c++ and still can not get right outlook of the pages.
1. The solution is absolutely broken for the text files, which contain Unicode (The NULL after every character just cuts the string off after the first character written into the pdf file).
2. I still can not get number of pages for the string from the UTF-8 txt file.
Here's the code:
void textToPdf(DebenuPDFLibraryDLL1016  &QP, const char *pathToTxt, std::string &outputPathString)
{
std::wstring str = get_file_contents(pathToTxt);

writeToLog(str);

double xPos = 50;
double startLine = 60;
double width = 520;

QP.SetOrigin(1);
int pid = QP.AddStandardFont(4);
QP.SelectFont(pid);
QP.SetTextSize(16);

QP.DrawWrappedText(xPos, startLine, width, str);

int saved = QP.SaveToFile( ctow(outputPathString.c_str()));
if (saved == 1)
{
writeToLog("Saved TXT to PDF file");
}
else
{
writeToLog("Problem saving TXT to PDF file");
}
}

/**
 * Get content of the file as string, for txt files only.
 */
std::wstring get_file_contents(const char *filename)
{
  std::wifstream in(filename, std::ios::in | std::ios::out);
  if (in)
  {
    std::wstring contents;

    in.seekg(0, std::ios::end);
    contents.resize(in.tellg());
    writeToLog(in.tellg());
    in.seekg(0, std::ios::beg);

    in.read(&contents[0], contents.size());
    in.close();


    return(contents);
  }
  throw(errno);
}

How can I  find number of pages needed for the wstring to be drawn on ?
Back to Top
AlexA_B View Drop Down
Beginner
Beginner


Joined: 08 Sep 14
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexA_B Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 14 at 2:55PM
My problem here even if I split the wstring into blocks with "\n" as delimeter I still can not be sure that every block will fit into the line.
How can I print VERY LONG string onto pdf ? How should I know number of pages needed for this string/wstring ? 

Thanks
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (1) Thanks(1)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 14 at 4:28PM
Alex,

DrawWrappedText is not really designed for this type of conversion as the function is also used internally for rendering form field appearance streams in the exact same way that Adobe does.


You may want to try DrawHTMLTextBox which has the option to return the overflow text which you can use to draw onto the next page and so on.  Here is the basic code to get it working.

            string html = "This is a very long line of text .....";

            QP.SetOrigin(1);
            QP.SetHTMLNormalFont("Default", QP.AddTrueTypeFont("Arial", 0));

            string overflowOutput = QP.DrawHTMLTextBox(50, 50, QP.PageWidth() - 100, 150, html);
            while (overflowOutput.Length != 0)
            {
                QP.NewPage();

                // Draw the remainder of the text box from the first DrawHTMLTextBox call

                overflowOutput = QP.DrawHTMLTextBox(50, 50, QP.PageWidth() - 100, 150, overflowOutput);
            }

Andrew.

Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 14 at 5:07PM
So the description in Refernce Guide is incomplete for DrawHTMLTextBox
Because there is no Return Values section.
I see this is mentioned in Description section but I think every developer looking into Return Values for such a specyfic info.

Please extend Refernce Guide.

Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
AlexA_B View Drop Down
Beginner
Beginner


Joined: 08 Sep 14
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexA_B Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 14 at 6:31PM
Thanks Andrew,
You really helped me out here.
The only thing to improve in your code - you will have to replace all "\n"'s into <BR>'s to keep line brakes. Other way - all the strings will be printed one after another and all end lines will be lost.
Here's my improved code:

void replaceAll(std::wstring &str, const std::wstring& from, const std::wstring& to)
{
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
}

}

void textToPdf(DebenuPDFLibraryDLL1016  &QP, const char *pathToTxt, std::string &outputPathString)
{
//TODO: the txt can be in unicode, which will not work here
std::wstring str = get_file_contents(pathToTxt);
//TODO: do not know how to handle texts which need more than 1 page.
writeToLog(str);

replaceAll(str,  L"\n", L"<BR>");

// double xPos = 50;
// double startLine = 60;
// double width = 520;

QP.SetOrigin(1);
int pid = QP.AddStandardFont(4);
QP.SelectFont(pid);
QP.SetTextSize(14);

//QP.DrawWrappedText(xPos, startLine, width, str);
std::wstring overflowStr = QP.DrawHTMLTextBox(5, 5, QP.PageWidth() - 10, QP.PageHeight() - 10, str);
while (overflowStr.length() > 0)
{
QP.NewPage();
overflowStr = QP.DrawHTMLTextBox(5, 5, QP.PageWidth() - 10, QP.PageHeight() - 10, overflowStr);
}

int saved = QP.SaveToFile( ctow(outputPathString.c_str()));
if (saved == 1)
{
writeToLog("Saved TXT to PDF file");
}
else
{
writeToLog("Problem saving TXT to PDF file");
}
}

Back to Top
AlexA_B View Drop Down
Beginner
Beginner


Joined: 08 Sep 14
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexA_B Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 14 at 7:22PM
My solution above works only for UTF-8 txt files with English only text.
Any ideas how I can use it for other languages ?
For example here's the file with text in Russian:
==================
 Здравствуйте, AlexA, у Вас 0 сообщений, 0 новых.
Показать Показать новые сообщения с Вашего последнего визита. / Показать новые ответы на Ваши сообщения.
  Учеба в Канаде с Инфостади
НачалоПомощьПоискПрофильЛичные сообщения ПользователиВыйти
===================
I saved it into a txt utf-8 file and tried my code to put it into a pdf.
Here's the output:
===================
 Ð Ð´Ñ Ð°Ð²Ñ Ñ Ð²Ñ Ð¹Ñ Ðμ, AlexA, Ñ Ð Ð°Ñ 0 Ñ Ð¾Ð¾Ð±Ñ Ðμний, 0 Ð½Ð¾Ð²Ñ Ñ .
Ð Ð¾ÐºÐ°Ð·Ð°Ñ Ñ Ð Ð¾ÐºÐ°Ð·Ð°Ñ Ñ Ð½Ð¾Ð²Ñ Ðμ Ñ Ð¾Ð¾Ð±Ñ ÐμÐ½Ð¸Ñ Ñ Ð Ð°Ñ Ðμго Ð¿Ð¾Ñ Ð»ÐμднÐμго
Ð²Ð¸Ð·Ð¸Ñ Ð°. / Ð Ð¾ÐºÐ°Ð·Ð°Ñ Ñ Ð½Ð¾Ð²Ñ Ðμ Ð¾Ñ Ð²ÐμÑ Ñ Ð½Ð° Ð Ð°Ñ Ð¸ Ñ Ð¾Ð¾Ð±Ñ ÐμÐ½Ð¸Ñ .
Ð£Ñ Ðμба в РанадÐμ Ñ Ð Ð½Ñ Ð¾Ñ Ñ Ð°Ð´Ð¸
Ð Ð°Ñ Ð°Ð»Ð¾Ð Ð¾Ð¼Ð¾Ñ Ñ Ð Ð¾Ð¸Ñ ÐºÐ Ñ Ð¾Ñ Ð¸Ð»Ñ Ð Ð¸Ñ Ð½Ñ Ðμ Ñ Ð¾Ð¾Ð±Ñ ÐμÐ½Ð¸Ñ Ð Ð¾Ð»Ñ Ð·Ð¾Ð²Ð°Ñ ÐμлÐ.

Any idea what to do with non-English string ?
Non-English utf-8 ? Unicode (utf-16) ?





Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 17 Sep 14 at 2:44AM
Thanks AndrewC for the new hint of using "DrawHTMLTextBox" and re-use its text overflow.

Thanks AlexA_B for your coding in C++ for the Text to PDF conversion.

Now I have my Text to PDF program working as I expected!

Here is my program:

    str pageText s.getfile("$my qm$/A Story.txt")
    ARRAY(str) a=s
    int Left = 20
    int Top = 30
    double PageWidth = qp.PageWidth() - 60
    double PageHeight = qp.PageHeight() - 60
    qp.SetOrigin(1)
    qp.SetHTMLNormalFont("Default", qp.AddTrueTypeFont("Arial", 0));

    // Convert text file into a HTML file
    for int'i 0 a.len
        pageText += _s.from(a "<br>")
    
    // Change font size
    pageText.insert("<font size='7'>" 0)    
    
    // Write HTML file to page
    str Overflow = qp.DrawHTMLTextBox(Left, Top, PageWidth, PageHeight, pageText)

    // Continue to write out if still left over
    rep
        if (Overflow.len=0) break
        qp.NewPage()
        Overflow = qp.DrawHTMLTextBox(Left, Top, PageWidth, PageHeight, Overflow)

    // Save to new PDF file
    qp.SaveToFile(_s.expandpath("$my qm$/out2.pdf"))
    run "$my qm$/out2.pdf"

Edited by Ben - 17 Sep 14 at 2:45AM
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 17 Sep 14 at 2:52AM
Hi AlexA_B

 I don't know what is the true fix for your Unicode problem. But in the mean time you can do a temporary fix like this.

Try to replace these 2 lines in your code:
...
    int pid = QP.AddStandardFont(4);
    QP.SelectFont(pid);
...

with this:
    int pid = qp.AddTrueTypeSubsettedFont("Times New Roman", "Здравствуйте, AlexA, у Вас 0 сообщений, 0 новых. Показать новые сообщения с Вашего последнего визита. / ответы на Ваши. Учеба в Канаде с Инфостади Начало Помощь Поиск Профиль Личные сообщения Пользователи Выйти", 0)
    qp.SetHTMLNormalFont("Default", pid)

and re-run your program.

Edited by Ben - 17 Sep 14 at 2:52AM
Back to Top
AndyD View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Apr 13
Location: UK
Status: Offline
Points: 54
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndyD Quote  Post ReplyReply Direct Link To This Post Posted: 17 Sep 14 at 8:32AM
AlexA_B, have you considered whether converting your raw text into rich text will support the other languages? I have not tried it for this example but found in an earlier project (Outputting rich text into a PDF form field), that rich text is able to contain more text info, font, size, style - bold, italic etc so may possible work for handling the Russian.
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 18 Sep 14 at 6:44AM
Originally posted by AlexA_B AlexA_B wrote:

My solution above works only for UTF-8 txt files with English only text.
Any ideas how I can use it for other languages ?
For example here's the file with text in Russian:

did you try something like this:

$iIDFont = $oQP.AddTrueTypeFont('Arial CE {1250}', 1)
$oQP.SelectFont($iIDFont)


Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 19 Sep 14 at 6:46AM
AlexA,

All of the functions in the library are expecting Unicode strings and not UTF-8 strings.

A new option in 11.11 is the use of option 4 in AddTrueTypeSubsettedFont.

It is very new but it allows you to create a Font and the characters that are used will be added to the font automatically if they are available in the font.  This will allow you to mix multiple languages and not have to think about what subset to use.

  QP.SetHTMLNormalFont("Default", QP.AddTrueTypeSubsettedFont("Arial", "", 4));

Andrew.
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 19 Sep 14 at 8:19PM
Thanks AndrewC for the new hint of using AddTrueTypeSubsettedFont with option #4. This is really a time-saving and useful option to deal with Unicode fonts. Tongue


Edited by Ben - 19 Sep 14 at 8:21PM
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 20 Sep 14 at 12:37AM
Hi AndrewC,

I've noticed that after using the new feature of AddTrueTypeSubsettedFont with option #4. There is a bug I might say, which is for the very first long string it encounters, the function "DrawHTMLTextBox" will not wrap up the text within the box width like before.

During testing for different text file, I've noticed there is always an overbound for the very first long string in the text that this function encountered, it will always produce an overbound of the box width limit. This is regardless of Unicode or Non-Unicode text files.

Could you take a look at that?

Edited by Ben - 20 Sep 14 at 12:39AM
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 22 Sep 14 at 5:32PM
Ben,

Thanks for reporting the bug.  Option #4 is only very new and needed some extra testing.  The DrawHTMLTextBox function is quite complex and there are multiple places that needed character widths earlier than I expected.

This fix will be included in the upcoming 11.12 release due out in the next couple of days.  Keep an eye out for it.  

Andrew.
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 22 Sep 14 at 8:24PM
Hi AndrewC,

Thanks for the update info. I'm looking forward for the new fix in the upcoming release.

Ben
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 23 Sep 14 at 11:22AM
Everyone,

Debenu Quick PDF Library 11.12 has just been released and includes the DrawHTMLTextBox fix.

It can be downloaded from here,

  http://www.debenu.com/products/development/debenu-pdf-library/updates/

Andrew.


Edited by AndrewC - 23 Sep 14 at 12:40PM
Back to Top
mLipok View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Apr 14
Location: Poland, Zabrze
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote mLipok Quote  Post ReplyReply Direct Link To This Post Posted: 23 Sep 14 at 11:36AM
Thanks.

Cheers.
mLipok


Edited by mLipok - 23 Sep 14 at 1:45PM
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600
Back to Top
Ben View Drop Down
Beginner
Beginner


Joined: 10 Sep 14
Location: San Pedro
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ben Quote  Post ReplyReply Direct Link To This Post Posted: 24 Sep 14 at 6:37PM
Hi AndrewC,

The mentioned bug has been fixed in the new release 11.12.

Thanks a lot for your quick response.

Ben
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