/// <summary> /// Save to PDF /// </summary> /// <param name="stream">Strema to write to</param> public void SaveToPdf(Stream stream) { //NativeMethods.cairo_select_font_face(_rsvgHandle, "serif", 0, 0); NativeMethods.RsvgDimensionData dim = new NativeMethods.RsvgDimensionData(); NativeMethods.rsvg_handle_get_dimensions(_rsvgHandle, ref dim); CairoWriteFunction cwf = new CairoWriteFunction(WriteToPDF); GCHandle handle1 = GCHandle.Alloc(stream); IntPtr parameter = (IntPtr)handle1; IntPtr surface = NativeMethods.cairo_pdf_surface_create_for_stream(cwf, parameter, dim.width, dim.height); IntPtr cairo = NativeMethods.cairo_create(surface); NativeMethods.rsvg_handle_render_cairo(_rsvgHandle, cairo); int status = NativeMethods.cairo_status(cairo); if (status > 0) { IntPtr s = NativeMethods.cairo_status_to_string(status); string ret = Marshal.PtrToStringAnsi(s); throw new Exception(ret); } NativeMethods.cairo_destroy(cairo); NativeMethods.cairo_surface_destroy(surface); }
internal static extern IntPtr cairo_pdf_surface_create_for_stream([MarshalAs(UnmanagedType.FunctionPtr)] CairoWriteFunction write_func, IntPtr closure, double width_in_points, double height_in_points);