Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic General question about printing and export to PDF (Read 5796 times)
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
General question about printing and export to PDF
May 6th, 2013 at 2:37pm
Print Post  
I'm trying to add support to let the user print the diagram or export it to PDF. My first efforts aren't very successful - please see attachments.

The two nodes in the print preview are the two tiny points in the upper left corner. Sad

My program uses MeasureUnit = pixel. I've seen here on the forum that there are lots of problems with that and printing.

So I guess my question is, what is the best and easiest way to make the program provide printing and export to PDF support? Change the program to not use MeasureUnit = pixel, and overcome the problems that entails, or get into various workarounds involving copying the diagram to a new hidden view and do printing and export to PDF from there?

Thanks.

PS. Maximum attachment size of 250 KB? Do you store them on floppy disks? Smiley
  

Snap6.png (Attachment deleted)
Snap7.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: General question about printing and export to PDF
Reply #1 - May 7th, 2013 at 6:15am
Print Post  
Hi,

Diagram.MeasureUnit is a simple wrapper around Graphics.PageUnit, and setting it to Pixel makes diagram coordinates correspond to device physical pixels.

Since printers' DPI count is much larger than screen's, you will have to scale  by the printer's DPI / screen's DPI to get the same size on paper. You can scale the print output by setting PrintOptions.Scale. Use printer's DefaultPageSettings.PrinterResolution.X value to find the DPI of a printer.

Alternatively, switch MeasureUnit temporarily to Point, and possibly scale by 72 / 96 to get closer to screen resolution.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: General question about printing and export to PDF
Reply #2 - May 7th, 2013 at 10:15am
Print Post  
Hi Stoyan, and thanks.

In trying to get something to work I've temporarily suppressed the background image, so I only have the two (custom) nodes. If I call PrintOptions.ScaleToPage() then PrintOptions gets set to 680! What does that mean? (I'm still using Diagram.MeasureUnit = pixel.)

But PrintOptions.Scale = 680 actually works - the two nodes are printed about where I would expect them to be. See attachment.

But the texts are not printed. These are custom nodes similar to those in the IconNodes sample program. What do I need to do to get the texts printed?

And one last question - it looks like the scaling has been done based on the printing being done in landscape orientation, but the preview doesn't automatically switch to landscape orientation. Is there a way of specifying which page orientation you want?

Thanks.
  

Snap8.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: General question about printing and export to PDF
Reply #3 - May 7th, 2013 at 1:58pm
Print Post  
Hi,

ScaleToPage applies the largest possible scale that still fits the diagram within a single page. I don't think scaling is done for landscape, however the print operation always preserves the diagram origin (it assumes the user would want to see the leftmost nodes printed at same offset it had on screen, especially if there is a BackgroundImage set). So in your sample the content rectangle that is scaled to fit the page includes the diagram origin and two nodes, and it look correctly scaled for a portrait page.

It should be enough to call DrawString from the node.Draw override to print texts. If the strings do not appear, try using a different font.Unit. I remember there were problems drawing scaled texts with some font units, not sure which ones exactly...

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: General question about printing and export to PDF
Reply #4 - May 8th, 2013 at 5:22am
Print Post  
Thanks for your help.

The thing that threw me about the "scale factor" of 680 was that it was so large. The printer does not have 680 times as many pixels per inch as the screen! Then I discovered that the so-called "scale factor" is actually a percentage.

You were right about Font.Unit being the problem with the text. The default unit of Point does not work, but Pixel does.
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: General question about printing and export to PDF
Reply #5 - May 8th, 2013 at 10:36am
Print Post  
OK, I got it working (I think). See attachment.

One more question, if I may: Do you have any suggestion as to how I can add some space between the header line and the diagram?

Thanks.
  

Snap9.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: General question about printing and export to PDF
Reply #6 - May 9th, 2013 at 5:59am
Print Post  
The header string is always printed immediately above the top margin at this time. The only way I can think of to add more space is by appending new lines to the header:

Code
Select All
var nl = Environment.NewLine;
diagramView.PrintOptions.HeaderFormat = "%D , Page %P" + nl + nl; 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: General question about printing and export to PDF
Reply #7 - May 13th, 2013 at 10:01am
Print Post  
OK, thanks, that actually works.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint