Problem with RVPrint and PDF export

General TRichView support forum. Please post your questions here
Post Reply
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Problem with RVPrint and PDF export

Post by Martian »

Hi there,
I found a problem with RVPrint/Preview and the same problem with PDF export because it use the same RVPrint.
Maybe it's not even RVPrint related so I cannot find the problem.
First of all I didn't change my code related to RVPrint/PDF export for years so I think the problem appeared after some TRichViewEdit update.
Just check these images.

This is the original how it appears in RVE:
Image

Here is how I see it in print preview (and in generated PDF):
Image

English text looks good but it's fake. Here is the PDF example with selected text:
Image

When you copy that selected text to clipboard you get this:
86)#!(779=>#M60>B1=)#8=#):1#;:("(;)1"#8<#):1#@8"0#N@O9MP%# Q%#B4#(77177B1=)#97#):()
):97#97#(#)9B1#8<#>"1()#8!!8")6=9)4#<8"#):1#R18!F1S7#T1!6HF9;#8<#/:9=(%#):1#/8BB6=97)#R(")4#8<
/:9=(#N//RQ#(=0#9)7#I1=1"(F#C1;"1)("4%#):1#R"17901=)#8<#/:9=(%#U9#V9=!9=>D# =0#9)#97#(#)9B1#8<
>"1()#0(=>1"#<8"#):1#1W97)9=>#@8"F0#8"01"#(
TRichView 18.3 but this problem appeared in v16 or v17. Cannot be sure.

P.S. Your llPDFLib export sample works fine.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with RVPrint and PDF export

Post by Sergey Tkachenko »

Assign RVPrint.MetafileCompatibility := True. In this mode, TRVPrint uses simplified text output, which must be understood by all PDF generation tools.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Re: Problem with RVPrint and PDF export

Post by Martian »

Ok this helped to get russian text shown in PDF and inside the RVPrintPreview but it's still not a text. I cannot use search function in PDF and when I copy something to clipboard I get this:
!"#$%&C'()" *)'+,"C(-& (+(#%. regular expressions, 672'. RegExp, RegEx, ,+'#. '"#:C263)
-%- '"C#"26)) 5 :/7 D7'=+%?()9 &0)2 37-62+ - 76$E"6/*%"(-& =+(-3$%&;-9 6
3746/'72+=- * /"26/", 76(7*+(()9 (+ -637%?07*+(-- ="/+6-=*7%7* (6-=*7%7*-
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with RVPrint and PDF export

Post by Sergey Tkachenko »

How do you create this PDF?
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Re: Problem with RVPrint and PDF export

Post by Martian »

Sergey Tkachenko wrote: Wed Apr 08, 2020 6:18 am How do you create this PDF?
In the previous version I used the old method published here years ago. Yesterday I updated it to the same way as in your sample from "..\ThirdParty\Export\LLPDFLib". But nothing changed. No difference.

BTW the second screenshot from my first post was from RVPrintPreview and not from PDF. So it's somewhere in RVPrint/RVPrintPreview...
I mean I get same picture in PDF and RVPrintPreview.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with RVPrint and PDF export

Post by Sergey Tkachenko »

By default, TRichView, TRVPrint and TRVReportHelper use an advanced text drawing method, which draws text using indexes of character glyphs (indexes of character images in fonts) instead of character codes. This method is the best for drawing multilanguage texts, and it must not cause problems in drawing on the screen, previewing, or printing on 99.99% printers.

But some PDF libraries (and PDF printers) have problems with this method. Other libraries create PDF that look correctly, but PDF viewers cannot copy text correctly in these PDF documents.

Assigning MetafileCompatibility = True must solve these problems. Please double check that you assign this property for TRVPrint or TRVReportHelper component that actually used to draw pages in PDF.
If you used the old PDF generation demo as a base, it used TRVReportHelper, not TRVPrint for drawing pages.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Re: Problem with RVPrint and PDF export

Post by Martian »

Sergey Tkachenko wrote: Wed Apr 08, 2020 8:04 am If you used the old PDF generation demo as a base, it used TRVReportHelper, not TRVPrint for drawing pages.
As I wrote both old and new PDF export demos produces the same result. Worse I see the same problem just in print preview dialog.
Assignation MetafileCompatibility=True helped to get Cyrillic chacracters in RVPrintPreview and in PDF but if I copy a russian text from PDF I get garbage in clipboard.
Image
No problems with Latin alphabet.

P.S. Old PDF export sample was able to use margins but this one just ignores them or I don't understand where to put them (RVPrint o FDocument).
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with RVPrint and PDF export

Post by Sergey Tkachenko »

1) Sorry, I do not understand what's the problem with the preview dialog, because this dialog does not allow copying text.

2) In the new demo, margins are loaded from files (RVF or RTF).
After loading:

Code: Select all

FDocument.MainDoc.RichView.LoadRTF(FileName)
, margins are loaded in FDocument.MainDoc.RichView.DocumentProperties.
Later, these margins are assigned to TRVPrint:

Code: Select all

FDocument.AssignToRVPrint(RVPrint1);
So, you can either change margins in FDocument.MainDoc.RichView.DocumentProperties before calling AssignToRVPrint, or change RVPrint1.Margins after.

3) I still cannot imagine other reason for this problem except for MetafileCompatibility = False.
In order to help, I need to reproduce this problem.
Please send me a a source document and a simple project that reproduce this problem.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Re: Problem with RVPrint and PDF export

Post by Martian »

Sergey Tkachenko wrote: Thu Apr 09, 2020 1:48 pm 1) Sorry, I do not understand what's the problem with the preview dialog, because this dialog does not allow copying text.
It's PDF. Tested in Adobe Acrobat CC and Foxit Phantom.
When I generate document with cyrillic characters I get PDF 3x bigger than PDF generated with virtual printer from foxit (or adobe).
Looks like RVPrint and llPDFLib encode cyrillic characters to something else...it only looks good but unsearchable, uncopiable.

Also is there an easy way to stretch to fit big pictures when generating PDF using llPDFLib?
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Re: Problem with RVPrint and PDF export

Post by Martian »

Sergey Tkachenko wrote: Thu Apr 09, 2020 1:48 pm So, you can either change margins in FDocument.MainDoc.RichView.DocumentProperties before calling AssignToRVPrint, or change RVPrint1.Margins after.
There is no .DocumentProperties defined in FDocument.MainDoc.RichView. Only DocProperties but it's TStringList.

And I still have a problem with PDF with cyrillic letters. Cannot send my project. It's just too big. Your sample works fine. Attached PDF I've got exported. Just try to open it and copy russian text then paste it to notepad.
test.zip
PDF inside
(128.36 KiB) Downloaded 2190 times
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Re: Problem with RVPrint and PDF export

Post by Martian »

BTW I didn't try. Your llPDFLib export example produce same damaged PDF.
It looks fine but when you copy some russian text from it you get garbage.
Attached small RVF to test.
Attachments
ToTestPDFexport.zip
(8.32 KiB) Downloaded 1957 times
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Re: Problem with RVPrint and PDF export

Post by Martian »

Still need help here.

Your llPDFLib export sample produces the same problematic PDF. Russian text not saved just garbage.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with RVPrint and PDF export

Post by Sergey Tkachenko »

I checked it... It looks like LLPDFLib always uses glyphs for text that is drawn using ExtTextOut, at least of it has the parameter specifying character positions (this function is used by TRVPrint in metafile-compatibility mode, and character positions are absolutely necessary in some cases, including justify alignment).
As a result, the text looks correct (if the correct font is used, its highly recommend to embed all used fonts in PDF), but it cannot be copied to the clipboard.

So the only solution is using other PDF generation libraries. For example, SynPDF does not have this problem.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Re: Problem with RVPrint and PDF export

Post by Martian »

So you say it's llPDFLib issue and cannot be fixed on your side? :?
Hope SynPDF is not so different from llPDFLib. I used llPDFLib (even purchased a license about 6 years ago) for years and didn't have this problem before.
Looks like it's time to move.

One more thing. How can I stretch big pictures to fit PDF page? See my first post where picture doesn't fit.
Post Reply