SharpPlot Reference > SharpPlot Methods > RenderPdf Method

SharpPlot.RenderPdf Method

Return completed chart rendered through through PDF engine.

The default is to have the document open in the user’s default mode, to embed all non-standard TrueType fonts and to compress the PDF content. You can set the PdfMode to open the outlines window, or to start with the document in full-screen view (useful for presentations).

By default, all fonts except the ‘base-14’ set will be embedded in the document automatically. If you are sure that all your potential viewers will have the fonts you have used, then set the noembed list to the names of the safe fonts, for example “Verdana,Perpetua” would be typical. This will make the document very much smaller, and the Acrobat Reader will usually be quite successful in substituting missing fonts if you are unlucky.

Compression is standard in PDF production (as well as reducing the document size it makes the material much harder to tamper with) but you may turn it off, either to assist in debugging a rendering problem or to preserve comments added with AddComment . Typically this would be to have a post-processing job catalogue the documents using tags saved in the comments.

Example

string mypdf = sp.RenderPdf();

Return Value

The result of this call is a string representation of an Adobe PDF. This may be written to file as text or returned via HTTP as type “application/pdf” to have it displayed by a web-browser.

   // Create a PDF and write the chart to it ...
    StreamWriter sw = new StreamWriter("Chart1.pdf",false,System.Text.Encoding.ASCII);
    string chart = sp.RenderPdf(PdfMode.ShowOutlines);
    sw.Write(chart);
    sw.Close();

Overloads

Embedding the PDF into a webpage

If you want to write the PDF content directly into a webpage, you should give it the correct content type “application/pdf”, and link to it with an appropriate <embed> tag such as:

<embed src="makepdf.aspx" height=300 width=640 type="application/pdf" >

The PdfMode parameter of RenderPDF should be set to FullScreen here, which causes the Acrobat Reader to occupy the entire frame set up by the <embed> tag with no toolbars or scrollbars. If you render a multipage PDF here, set the flag to ShowOutlines and allow enough extra space for the outline pane and Acrobat Reader toolbars. You will probably need to experiment to get the height and width to look correct.

See also ...

SharpPlot Members | SharpPlot.SavePdf Method | PdfMode Enumeration


Send comments on this topic
© Dyalog Ltd 2021