using Microsoft.Win32;
using RGiesecke.DllExport;
using SelectPdf;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Test
{
public class gcCommon
{
[DllExport(CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.Bool)]
public static bool GeneratePdfFile
(
[param: MarshalAs(UnmanagedType.BStr)]string content,
[param: MarshalAs(UnmanagedType.BStr)]string filename
)
{
try
{
string pdf_page_size = PdfPageSize.A4.ToString();
PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true);
string pdf_orientation = PdfPageOrientation.Portrait.ToString();
PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true);
// instantiate a
html to pdf converter object
HtmlToPdf converter = new HtmlToPdf();
// set converter options
converter.Options.PdfPageSize = pageSize;
converter.Options.PdfPageOrientation = pdfOrientation;
converter.Options.MarginLeft = 35;
converter.Options.MarginRight = 35;
converter.Options.MarginTop = 20;
converter.Options.MarginBottom = 20;
//converter.Options.WebPageWidth = webPageWidth;
//converter.Options.WebPageHeight = webPageHeight;
// create a new pdf document converting an
url
SelectPdf.PdfDocument doc = converter.ConvertHtmlString(content);
// save pdf document
doc.Save(@filename);
// close pdf document
doc.Close();
}
catch (
Exception e)
{
MessageBox.Show(e.Message);
}
return true;
}
}
}