Page Index Toggle Pages: [1] 2 3 ... 5 Send TopicPrint
Very Hot Topic (More than 25 Replies) how to set wpf spreadsheet export pdf font. (Read 22450 times)
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
how to set wpf spreadsheet export pdf font.
May 27th, 2020 at 7:26am
Print Post  
Hello, How to set the right font for export to PDF? Meaning different language characters.  Both csv and xlsx are correct. Only happen when export to PDF. Thanks
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: how to set wpf spreadsheet export pdf font.
Reply #1 - May 27th, 2020 at 12:08pm
Print Post  
Hi,

If you are getting incorrect PDFs from text containing CJK glyphs, try these settings -

pdfex.AutoDetectEncoding = false;
pdfex.DefaultEncoding = Encoding.Unicode;

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #2 - May 27th, 2020 at 12:47pm
Print Post  
Thanks for the reply.

Apply the code like following

                       var activeSheet = workbookView.ActiveWorksheet;
                       PdfExporter pdfExporter = new PdfExporter();
                       pdfExporter.AutoDetectEncoding = false;
                       pdfExporter.DefaultEncoding = Encoding.Unicode;
                       pdfExporter.Export(activeSheet, dialog.FileName);




The original data is like :

OrderID      DSID      warehouse      訂單日期      pv      Total Sales
703012674      700187543      20867      2020/5/14 上午 12:00:00      185      2276
703012676      693739      21300      2020/5/14 上午 12:00:00      120      1596


After apply the code the data is not readable and like


P s e f s J E E T J E x b s f i p v t fYª%V5•6Ç q w U p u b m ! T b m f t
8 1 4 1 2 3 7 8 5 8 1 1 2 9 8 6 5 4 3 1 9 7 8 3 1 3 1 0 6 0 2 5 2 9 6 3 3 8 7
8 1 4 1 2 3 7 8 7 7 : 4 8 4 : 3 2 4 1 1 3 1 3 1 0 6 0 2 5 2 3 1 2 6 : 7




This is data export from PDF export

OrderID DSID warehouse U®eåg pv Total Sales
703012674700187543 20867 2020/5/14 185 2276
703012676 693739 21300 2020/5/14 120 1596


This is the data should shown

OrderID      DSID      warehouse      訂單日期      pv      Total Sales
703012674      700187543      20867      2020/5/14 上午 12:00:00      185      2276
703012676      693739      21300      2020/5/14 上午 12:00:00      120      1596


Thanks for the help

  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: how to set wpf spreadsheet export pdf font.
Reply #3 - May 27th, 2020 at 4:20pm
Print Post  
It seems to export well enough in my test shown in attached screenshot, opening the PDF in Adobe Reader or Chrome. I also had to set cells' Style.FontName to Unicode-enabled font in order to see glyphs in the spreadsheet itself -

var range = sheet.CellRanges[0, 0, 1000, 10000];
range.Style.FontName = "Arial Unicode MS";

The PDF's looking strange in Firefox and Edge though, were you opening your PDF in one of these browsers?

Regards,
Slavcho
  

test_002.pdf ( 186 KB | 189 Downloads )
Untitled_010.png ( 83 KB | 187 Downloads )
Untitled_010.png
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #4 - May 28th, 2020 at 12:25am
Print Post  
The text shown on the spreadsheet is correct but it not correct when export to PDF. Other export types are OK (XLSX, CSV). I try to display on Chrome, Edge and PDF reader but failed on all of them.   On the PDF reader, it failed to open the file with error message show on the screen.
  

chrome.png ( 40 KB | 179 Downloads )
chrome.png
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #5 - May 28th, 2020 at 12:26am
Print Post  
Open from the acrobatreader
  

acrobatreader.png ( 10 KB | 181 Downloads )
acrobatreader.png
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #6 - May 28th, 2020 at 12:26am
Print Post  
Open from the Edge
  

Edge.png ( 35 KB | 174 Downloads )
Edge.png
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #7 - May 28th, 2020 at 12:27am
Print Post  
The data itself
  

spreadsheet.png ( 8 KB | 181 Downloads )
spreadsheet.png
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #8 - May 28th, 2020 at 12:29am
Print Post  
Here is the code


           private void GenerateRandomFont(ref Cell cell)
           {
                 var style = cell.Style;

                 style.FontName = "MingLiU";
                 style.FontBold = false;
                 style.FontItalic = false;
                 //style.FontSize = 14;
           }
           private void menuItemPdf_Click(object sender, RoutedEventArgs e)
           {
                 SaveFileDialog dialog = new SaveFileDialog();

                 dialog.Filter = "PDF Files (*.pdf)|*.pdf|All files (*.*)|*.*||";
                 if (dialog.ShowDialog(this) == true)
                 {
                       var activeSheet = workbookView.ActiveWorksheet;
                       PdfExporter pdfExporter = new PdfExporter();
                       //pdfExporter.AutoDetectEncoding = false;
                       //pdfExporter.DefaultEncoding = Encoding.Unicode;
                       pdfExporter.Export(activeSheet, dialog.FileName);
                 }
           }
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #9 - May 28th, 2020 at 3:06am
Print Post  
zipped  pdf file
  

ddd.rar ( 41 KB | 194 Downloads )
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: how to set wpf spreadsheet export pdf font.
Reply #10 - May 28th, 2020 at 5:24am
Print Post  
What does that message mean in English?

Quote:
//pdfExporter.AutoDetectEncoding = false;
//pdfExporter.DefaultEncoding = Encoding.Unicode;


You will need to uncomment these to get PDFs working in Reader / Chrome.
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #11 - May 28th, 2020 at 6:01am
Print Post  
meaning "Error processing page 110"

https://community.adobe.com/t5/acrobat-reader/error-processing-page-110/td-p/970
1498?page=1

Unmask the comments and run the data. The same set of data is not correct .

I try to add the font from adobe but no luck and change the PDF library from 1.3.2.400 to 1.3.2.450 still not working


Thanks
  

chrome_001.png ( 67 KB | 172 Downloads )
chrome_001.png
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: how to set wpf spreadsheet export pdf font.
Reply #12 - May 28th, 2020 at 6:08am
Print Post  
It worked for me with only a few strings from your sample data, so I guess something else from all the cells is breaking it. Please attach the spreadsheet file you are exporting and our developer will check.
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: how to set wpf spreadsheet export pdf font.
Reply #13 - May 28th, 2020 at 6:28am
Print Post  
the attach file the data export to xlsx
  

bbb.xlsx ( 21 KB | 228 Downloads )
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: how to set wpf spreadsheet export pdf font.
Reply #14 - May 30th, 2020 at 9:05am
Print Post  
PDF exported from this file renders correctly for us in Adobe Reader and Chrome.

Code
Select All
var imp = new ExcelImporter();
imp.View = wbview;
imp.Import("bbb.xlsx", wbview.Workbook);
...
var activeSheet = wbview.ActiveWorksheet;
PdfExporter pdfExporter = new PdfExporter();
pdfExporter.AutoDetectEncoding = false;
pdfExporter.DefaultEncoding = Encoding.Unicode;
pdfExporter.Export(activeSheet, @"D:\test.pdf"); 



Does the attached PDF work on your side if you open it in Adobe / Chrome? If our file works but yours does not, it might mean PdfExporter's font embedding code fails for some reason when running on your system.
  

test_pdf.zip ( 64 KB | 193 Downloads )
Untitled_011.png ( 463 KB | 203 Downloads )
Untitled_011.png
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 ... 5
Send TopicPrint