[WPF] Teechart Print

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Geomisure
Newbie
Newbie
Posts: 10
Joined: Tue Nov 16, 2021 12:00 am

[WPF] Teechart Print

Post by Geomisure » Wed Jul 20, 2022 10:06 am

Good Morning,

is there any way to avoid Chart Canvas to be resized when it's been exported for printing?

Example:

Code: Select all

private void testdummyprint()
        {
            var prtDlg = new PrintDialog();
            FlowDocument doc = new FlowDocument();
            doc.Name = "Test";

            doc.PageHeight = (96 / 2.54)*29.7;
            doc.PageWidth = (96 / 2.54) * 21;

            doc.ColumnWidth = doc.PageWidth;
            doc.ColumnGap = 0;

            var tb = new Table();
            var tr = new TableRow();


            var s1 = new MemoryStream();
            var s2 = new MemoryStream();
            var s3 = new MemoryStream();

            var image1 = new BitmapImage();
            var image2 = new BitmapImage();
            var image3 = new BitmapImage();

            t1.Export.Image.Bitmap.Save(s1, t1.Bitmap(doc.PageWidth / 3, doc.PageHeight), doc.PageWidth / 3, doc.PageHeight);
            t2.Export.Image.Bitmap.Save(s2, t2.Bitmap(doc.PageWidth / 3, doc.PageHeight), doc.PageWidth / 3, doc.PageHeight);
            t3.Export.Image.Bitmap.Save(s3, t3.Bitmap(doc.PageWidth / 3, doc.PageHeight), doc.PageWidth / 3, doc.PageHeight);

            image1.BeginInit();
            image1.CacheOption = BitmapCacheOption.OnLoad;
            s1.Position = 0;
            image1.StreamSource = s1;
            image1.EndInit();
            image2.BeginInit();
            s2.Position = 0;
            image2.CacheOption = BitmapCacheOption.OnLoad;
            image2.StreamSource = s2;
            image2.EndInit();
            image3.BeginInit();
            s3.Position = 0;
            image3.CacheOption = BitmapCacheOption.OnLoad;
            image3.StreamSource = s3;
            image3.EndInit();
            var block1 = new BlockUIContainer(new System.Windows.Controls.Image() { Source = image1 });
            var block2 = new BlockUIContainer(new System.Windows.Controls.Image() { Source = image2 });
            var block3 = new BlockUIContainer(new System.Windows.Controls.Image() { Source = image3 });

            tr.Cells.Add(new TableCell(block1));
            tr.Cells.Add(new TableCell(block2));
            tr.Cells.Add(new TableCell(block3));

            var tgr = new TableRowGroup();
            tgr.Rows.Add(tr);
            tb.RowGroups.Add(tgr);

            doc.Blocks.Add(tb);

            IDocumentPaginatorSource idpSource = doc;
            prtDlg.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing.");
        }
In this case I've a window with 3 tcharts where each one has a series of line type , filled with random values.

i want to print all charts in one page, but with function linked all canvas chart are resized to new size.
there's any way to avoid this effect?

Thanks

Best Regards,

Geomisure
Attachments
WpfTest.rar
(412.74 KiB) Downloaded 725 times

Geomisure
Newbie
Newbie
Posts: 10
Joined: Tue Nov 16, 2021 12:00 am

Re: [WPF] Teechart Print

Post by Geomisure » Mon Jul 25, 2022 2:55 pm

no suggestions?

in addiction i've noticed that picture exported is Blurry... like pixellized...
This is the max quality of TChart under WPF??????!!!!????

Marc
Site Admin
Site Admin
Posts: 1274
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: [WPF] Teechart Print

Post by Marc » Tue Jul 26, 2022 8:15 am

Hello Geomisure,

Sorry with the delay replying. I had downloaded the attached file to check the project but the file seems to be corrupted; it doesn't unzip. Could you re-submit it please, or send a copy to info@steema.com if it is not very large.

I'll see if I can extract part of the code you pasted to mockup a testof it.

Regards,
Marc Meumann
Steema Support

Marc
Site Admin
Site Admin
Posts: 1274
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: [WPF] Teechart Print

Post by Marc » Tue Jul 26, 2022 8:37 am

Hello Geomisure,

I've been able to take a look at the code and run it.

The settings here:

Code: Select all

Chart.Export.Image.Bitmap.Save(s1, Chart.Chart.Bitmap(doc.PageWidth / 3, doc.PageHeight), doc.PageWidth / 3, doc.PageHeight);
Chart.Export.Image.Bitmap.Save(s2, Chart.Chart.Bitmap(doc.PageWidth / 3, doc.PageHeight), doc.PageWidth / 3, doc.PageHeight);
Chart.Export.Image.Bitmap.Save(s3, Chart.Chart.Bitmap(doc.PageWidth / 3, doc.PageHeight), doc.PageWidth / 3, doc.PageHeight);
..are stretching the chart to the page dimensions. You could set the size you wish here; including a check to maintain the aspect ratio of the Chart... ie. use the dimension you wish to dominate such as "doc.PageWidth / 3" and multiply that by the aspect ratio (by previously determining the chart width/height)

Regards,
Marc
Steema Support

Geomisure
Newbie
Newbie
Posts: 10
Joined: Tue Nov 16, 2021 12:00 am

Re: [WPF] Teechart Print

Post by Geomisure » Tue Jul 26, 2022 10:46 am

Hi Marc,

thx for response.
In attachment , an upgrade for the examples based with support windows.
There i pre set windows size aa Page A4, after all i build chart and export then such as original idea.

But if you zoom che report generated i can see an high difference in blurry between first line and images of tchart.

Have you any idea about what's wrong? (cause in this case the resizing of image its nothing, anyway it will generated blurry...)

how frustrating, i will not to be obbligated in rollback to windows form to avoid this problem...

Hopping in any help

Best Regards,

Geomisure
Attachments
WpfTest.7z
(220.36 KiB) Downloaded 758 times

Geomisure
Newbie
Newbie
Posts: 10
Joined: Tue Nov 16, 2021 12:00 am

Re: [WPF] Teechart Print

Post by Geomisure » Wed Jul 27, 2022 2:13 pm

No solution?

I must rollback to windows form to obtain accepteable image?

Best Regards,

Geomisure

Marc
Site Admin
Site Admin
Posts: 1274
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: [WPF] Teechart Print

Post by Marc » Wed Jul 27, 2022 3:23 pm

Hello Geomisure,

I'm not seeing an obvious reduction in quality. I attach the output obtained printing to pdf from your test project. Is this what you're expecting to see?

Thanks,
Marc
Attachments
wpfcharts.zip
(152.74 KiB) Downloaded 704 times

Geomisure
Newbie
Newbie
Posts: 10
Joined: Tue Nov 16, 2021 12:00 am

Re: [WPF] Teechart Print

Post by Geomisure » Wed Jul 27, 2022 3:29 pm

zoom in on pdf generate.
(ctrl + )

you will can see a great difference between legend text and "header text" on first line.
The same issue is obtained with a "scaling" of tchart bitmap export.
Only (worst) way to not blurry image is to printvisual from window (but it depend on window rendering and in my case it's not accepteable).

Best Regards,

Geomisure

edit: in attachment 2 screen for better explenation
Attachments
example_with_print_visual.png
example_with_print_visual.png (46.46 KiB) Viewed 12346 times
example_with bitmap_exported.png
example_with bitmap_exported.png (38.24 KiB) Viewed 12346 times

Marc
Site Admin
Site Admin
Posts: 1274
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: [WPF] Teechart Print

Post by Marc » Wed Jul 27, 2022 4:25 pm

Hello Geomisure,

I'll have a think about options. One might be to increase the resolution of the bitmap. You may need to up font sizes.

ie.

Code: Select all

t1.Export.Image.PNG.Save(s1, t1.Bitmap((doc.PageWidth / 3 * 2), doc.PageHeight *  2), doc.PageWidth / 3, doc.PageHeight);
t2.Export.Image ...etc
Regards,
Marc
Steema Support

Geomisure
Newbie
Newbie
Posts: 10
Joined: Tue Nov 16, 2021 12:00 am

Re: [WPF] Teechart Print

Post by Geomisure » Thu Jul 28, 2022 9:13 am

Hi Marc,

for first option it's not possible.
first size for chart.bitmap(x,y) must be the same of last 2 size parameter. otherwise image is cutted (even if you set stretchmode = fill to image)

for second option i've increased size by 1 unit and R&D manager accept this compromise, however image quality it's visibile blurry against text (an example in attach)

it's possibile to obtain an image with the same quality of metafile obtained in winforms version?
Sorry for insistence but it's the main critical section in out software and must be better quality as possible

Best Regards,
Geomisure
Attachments
document.zip
(270.61 KiB) Downloaded 759 times

Marc
Site Admin
Site Admin
Posts: 1274
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: [WPF] Teechart Print

Post by Marc » Thu Jul 28, 2022 5:01 pm

Hello Geomisure,

Re.
for second option
Are you referring to the use of this code?

Code: Select all

t1.Export.Image.PNG.Save(s1, t1.Bitmap((doc.PageWidth / 3 * 2), doc.PageHeight *  2), doc.PageWidth / 3, doc.PageHeight);
t2.Export.Image.PNG.Save(s2, t2.Bitmap((doc.PageWidth / 3 * 2), doc.PageHeight * 2), doc.PageWidth / 3, doc.PageHeight);
t3.Export.Image.PNG.Save(s3, t3.Bitmap((doc.PageWidth / 3 * 2), doc.PageHeight * 2), doc.PageWidth / 3, doc.PageHeight);
(that gives result like attachment)

If you were using metafile from the Winform application then the quality will be different as it is not pixel orientated, Doing a single export from the WPF charts as a pdf gives you a similar quality output but as soon as it is rendered to bitmap and resized the quality is lost.

There is a multichart pdf feature in recent versions of TeeChart that uses PdfSharpCore but it's going to give you a chart per page which is not what you want, I'm taking a look at options to see if they can be combined.

ie.

Code: Select all

t1.Export.Image.PDF.MultiChart.Add(new Steema.TeeChart.WPF.Export.MultiPDF
            {
                Chart = t2,
                Bounds = new System.Windows.Rect(200, 200, 1000, 1000),
                PageSize = Steema.TeeChart.Export.PDFPageSize.A4,
                Orientation = PdfSharpCore.PageOrientation.Portrait,
                Position = Steema.TeeChart.Export.PDFPosition.Custom
            });
reference here: https://github.com/ststeiger/PdfSharpCore

Regards,
Marc
Attachments
wpfchart_resize.zip
(281.6 KiB) Downloaded 717 times
Steema Support

Geomisure
Newbie
Newbie
Posts: 10
Joined: Tue Nov 16, 2021 12:00 am

Re: [WPF] Teechart Print

Post by Geomisure » Fri Jul 29, 2022 9:10 am

Hi Marc,

nope second option refer to increase title\label font size (i've increased from 6 ot 7 and R&D manager accepted compromise).

about your option code i still having image misformed by yours (check attachment test.zip , olther is source code).

any help?

Best Regards,
Geomisure
Attachments
WpfTest_source.zip
(15.75 KiB) Downloaded 752 times
test.zip
(174.66 KiB) Downloaded 732 times

Marc
Site Admin
Site Admin
Posts: 1274
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: [WPF] Teechart Print

Post by Marc » Fri Jul 29, 2022 11:07 am

Hello Geomisure,

In the sample code you sent, the multiplication (x 2) for the height has been omitted, hence the Charts are only filling half the page.

ie. should be:;

Code: Select all

t1.Export.Image.PNG.Save(s1, t1.Bitmap((doc.PageWidth / 3 * 2), doc.PageHeight * 2), doc.PageWidth / 3, doc.PageHeight);
t2.Export.Image.PNG.Save(s2, t2.Bitmap((doc.PageWidth / 3 * 2), doc.PageHeight * 2), doc.PageWidth / 3, doc.PageHeight);
t3.Export.Image.PNG.Save(s3, t3.Bitmap((doc.PageWidth / 3 * 2), doc.PageHeight * 2), doc.PageWidth / 3, doc.PageHeight);
Regards,
Marc
Steema Support

Post Reply