create PDFExporter exporter implementation.
this works, with included version of HiQPdf. (or i may be using another version..ARGH DLL HELL)
This commit is contained in:
parent
27a6ae4631
commit
d16d01ad3e
BIN
RaceLapTimer/PDFExporter/HiQPdf.dep
Normal file
BIN
RaceLapTimer/PDFExporter/HiQPdf.dep
Normal file
Binary file not shown.
BIN
RaceLapTimer/PDFExporter/HiQPdf.dll
Normal file
BIN
RaceLapTimer/PDFExporter/HiQPdf.dll
Normal file
Binary file not shown.
BIN
RaceLapTimer/PDFExporter/HiQPdf.rda
Normal file
BIN
RaceLapTimer/PDFExporter/HiQPdf.rda
Normal file
Binary file not shown.
@ -30,17 +30,8 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Syncfusion.Compression.Base, Version=14.1451.0.46, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Syncfusion.HtmlToPdfConverter451.14.1.0.46\lib\net451\Syncfusion.Compression.Base.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Syncfusion.HtmlConverter.Base, Version=14.1451.0.46, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Syncfusion.HtmlToPdfConverter451.14.1.0.46\lib\net451\Syncfusion.HtmlConverter.Base.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Syncfusion.Pdf.Base, Version=14.1451.0.46, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Syncfusion.HtmlToPdfConverter451.14.1.0.46\lib\net451\Syncfusion.Pdf.Base.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="HiQPdf">
|
||||
<HintPath>.\HiQPdf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@ -62,9 +53,6 @@
|
||||
<Name>Interfaces</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@ -1,22 +1,74 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using HiQPdf;
|
||||
using Interfaces;
|
||||
using Syncfusion.HtmlConverter;
|
||||
using Syncfusion.Pdf;
|
||||
using Syncfusion.Pdf.Graphics;
|
||||
|
||||
namespace PDFExporter
|
||||
{
|
||||
public class PdfExporter:IFileExporter
|
||||
{
|
||||
private Stream str = new MemoryStream();
|
||||
public Stream Export(string fileContent, string baseUrl)
|
||||
//private Stream str = new MemoryStream();
|
||||
public void Export(string fileContent, string baseUrl, out Stream exportStream)
|
||||
{
|
||||
var t = new Thread(()=>DoExport(fileContent, baseUrl));
|
||||
t.SetApartmentState(ApartmentState.STA);
|
||||
t.Start();
|
||||
t.Join();
|
||||
return str;
|
||||
//Stream pdfExportStream = new MemoryStream();
|
||||
//var t = new Thread(new ParameterizedThreadStart(DoExport));//()=>DoExport(fileContent, baseUrl));
|
||||
//var t2 = Task.Factory.StartNew(() => DoExport(fileContent, baseUrl));
|
||||
|
||||
//t.SetApartmentState(ApartmentState.STA);
|
||||
//t.Start();
|
||||
//t.Join();
|
||||
|
||||
//exportStream = t2.Result;
|
||||
//FileStream fileStream = File.Create("pdfexportertst.pdf", (int)t2.Result.Length);
|
||||
//// Initialize the bytes array with the stream length and then fill it with data
|
||||
//byte[] bytesInStream = new byte[t2.Result.Length];
|
||||
//t2.Result.Read(bytesInStream, 0, bytesInStream.Length);
|
||||
//// Use write method to write to the file specified above
|
||||
//fileStream.Write(bytesInStream, 0, bytesInStream.Length);
|
||||
//fileStream.Flush(true);
|
||||
//fileStream.Close();
|
||||
////CopyStream(t2.Result, fs);
|
||||
//Debug.WriteLine(t2.Result.Length);
|
||||
|
||||
// instantiate a html to pdf converter object
|
||||
HtmlToPdf converter = new HtmlToPdf();
|
||||
converter.MediaType = "print";
|
||||
converter.RunJavaScript = true;
|
||||
converter.WaitBeforeConvert = 1;
|
||||
|
||||
converter.Document.FitPageWidth = true;
|
||||
converter.Document.ForceFitPageWidth = true;
|
||||
converter.BrowserZoom = 135;
|
||||
converter.Document.Properties.CreationDate = DateTime.UtcNow;
|
||||
// set converter options
|
||||
converter.Document.PageSize = PdfPageSize.A4;
|
||||
converter.Document.PageOrientation = PdfPageOrientation.Portrait;
|
||||
//converter.Options.WebPageWidth = webPageWidth;
|
||||
//converter.Options.WebPageHeight = webPageHeight;
|
||||
|
||||
// create a new pdf document converting an url
|
||||
exportStream = new MemoryStream();
|
||||
converter.ConvertHtmlToStream(fileContent, baseUrl, exportStream);
|
||||
|
||||
// save pdf document
|
||||
//doc.Save(Response, false, "Sample.pdf");
|
||||
|
||||
// close pdf document
|
||||
//doc.Close();
|
||||
|
||||
}
|
||||
|
||||
private void CopyStream(Stream input, Stream output)
|
||||
{
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
int read;
|
||||
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
output.Write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
public ExportProviderDetails GetDetails()
|
||||
@ -26,54 +78,90 @@ namespace PDFExporter
|
||||
Type = "PDF"
|
||||
};
|
||||
}
|
||||
|
||||
void DoExport(string fileContent, string baseUrl)
|
||||
{
|
||||
//var pdfExporter = new HtmlToPdfConverter();
|
||||
//var settings2 = new IEConverterSettings();
|
||||
//settings2.AdditionalDelay = 2000;
|
||||
//pdfExporter.ConverterSettings = settings2;
|
||||
//PdfDocument doc = pdfExporter.Convert(fileContent, baseUrl);
|
||||
|
||||
//Stream DoExport(string fileContent, string baseUrl)
|
||||
//{
|
||||
// #region MyRegion
|
||||
// //var pdfExporter = new HtmlToPdfConverter();
|
||||
// //var settings2 = new IEConverterSettings();
|
||||
// //settings2.AdditionalDelay = 2000;
|
||||
// //pdfExporter.ConverterSettings = settings2;
|
||||
// //PdfDocument doc = pdfExporter.Convert(fileContent, baseUrl);
|
||||
|
||||
|
||||
var conv = new HtmlToPdfConverter();
|
||||
// //var conv = new HtmlToPdfConverter();
|
||||
|
||||
PdfDocument document = new PdfDocument();
|
||||
//Set page margins and dimensions.
|
||||
// //PdfDocument document = new PdfDocument();
|
||||
// ////Set page margins and dimensions.
|
||||
|
||||
PdfUnitConvertor convertor = new PdfUnitConvertor();
|
||||
// //PdfUnitConvertor convertor = new PdfUnitConvertor();
|
||||
|
||||
float width = convertor.ConvertToPixels(document.PageSettings.Width, PdfGraphicsUnit.Point);
|
||||
float height = convertor.ConvertToPixels(document.PageSettings.Height, PdfGraphicsUnit.Point);
|
||||
// //float width = convertor.ConvertToPixels(document.PageSettings.Width, PdfGraphicsUnit.Point);
|
||||
// //float height = convertor.ConvertToPixels(document.PageSettings.Height, PdfGraphicsUnit.Point);
|
||||
|
||||
var settings = new IEConverterSettings();
|
||||
// //var settings = new IEConverterSettings();
|
||||
|
||||
settings.EnableHyperLink = true;
|
||||
settings.EnableJavaScript = true;
|
||||
settings.SplitImages = false;
|
||||
settings.SplitTextLines = false;
|
||||
// //settings.EnableHyperLink = true;
|
||||
// //settings.EnableJavaScript = true;
|
||||
// //settings.SplitImages = false;
|
||||
// //settings.SplitTextLines = false;
|
||||
|
||||
settings.Margin.All = 20.0f;
|
||||
// //settings.Margin.All = 20.0f;
|
||||
|
||||
settings.PdfPageSize = PdfPageSize.A4;
|
||||
// //settings.PdfPageSize = PdfPageSize.A4;
|
||||
|
||||
conv.ConverterSettings = settings;
|
||||
// //conv.ConverterSettings = settings;
|
||||
|
||||
//Convert the URL/HTML string by providing the required width and height.
|
||||
var doc = conv.Convert(@"http://www.bbc.co.uk", width, height, AspectRatio.KeepWidth);
|
||||
doc.PageSettings.Size = PdfPageSize.A4;
|
||||
doc.PageSettings.SetMargins((float)20.0f);
|
||||
// ////Convert the URL/HTML string by providing the required width and height.
|
||||
// //var doc = conv.Convert(@"http://www.bbc.co.uk", width, height, AspectRatio.KeepWidth);
|
||||
// //doc.PageSettings.Size = PdfPageSize.A4;
|
||||
// //doc.PageSettings.SetMargins((float)20.0f);
|
||||
|
||||
doc.Save("c:\\zzz\\test3.pdf");
|
||||
//doc.Close(true);
|
||||
// //doc.Save("c:\\zzz\\test3.pdf");
|
||||
// ////doc.Close(true);
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
doc.Save(ms);
|
||||
doc.Close(true);
|
||||
ms.CopyTo(str);
|
||||
ms.Flush();
|
||||
ms.Close();
|
||||
ms.Dispose();
|
||||
}
|
||||
|
||||
// #endregion
|
||||
// // instantiate a html to pdf converter object
|
||||
// HtmlToPdf converter = new HtmlToPdf();
|
||||
|
||||
// // set converter options
|
||||
// converter.Options.PdfPageSize = PdfPageSize.A4;
|
||||
// converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
|
||||
// converter.Options.CssMediaType = HtmlToPdfCssMediaType.Print;
|
||||
// //converter.Options.WebPageWidth = webPageWidth;
|
||||
// //converter.Options.WebPageHeight = webPageHeight;
|
||||
|
||||
// // create a new pdf document converting an url
|
||||
// PdfDocument doc = converter.ConvertHtmlString(fileContent, baseUrl);
|
||||
// doc.Margins = new PdfMargins(20.0f, 20.0f,20.0f,20.0f);
|
||||
// // save pdf document
|
||||
// //doc.Save(Response, false, "Sample.pdf");
|
||||
|
||||
// // close pdf document
|
||||
// //doc.Close();
|
||||
// File.Delete("plugintest.pdf");
|
||||
// //doc.Save("plugintest.pdf");
|
||||
// MemoryStream ms = new MemoryStream();
|
||||
// doc.Save(ms);
|
||||
// //doc.Save(exportStream);
|
||||
// //FileStream fs = new FileStream("pdfexporterfs2.pdf", FileMode.Create);
|
||||
// //CopyStream(ms, fs);
|
||||
// //fs.Flush(true);
|
||||
// //fs.Close();
|
||||
// //fs.Dispose();
|
||||
// //doc.Save(fs);
|
||||
// //ms.WriteTo(fs);
|
||||
// //fs.Flush(true);
|
||||
// //fs.Close();
|
||||
// //fs.Dispose();
|
||||
|
||||
// doc.Close();
|
||||
// return ms;
|
||||
// //ms.CopyTo(str);
|
||||
// //ms.Flush();
|
||||
// //ms.Close();
|
||||
// //ms.Dispose();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Syncfusion.HtmlToPdfConverter451" version="14.1.0.46" targetFramework="net452" />
|
||||
</packages>
|
||||
Loading…
Reference in New Issue
Block a user