|
@@ -20,6 +20,8 @@ using InABox.Core;
|
|
|
using InABox.Core.Reports;
|
|
|
using InABox.Scripting;
|
|
|
using InABox.Wpf.Reports.CustomObjects;
|
|
|
+using Syncfusion.Pdf;
|
|
|
+using Syncfusion.Pdf.Parsing;
|
|
|
using XmlDocument = System.Xml.XmlDocument;
|
|
|
|
|
|
namespace InABox.Wpf.Reports
|
|
@@ -251,41 +253,43 @@ namespace InABox.Wpf.Reports
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public static byte[] CompressPDF(byte[] original)
|
|
|
+ {
|
|
|
+
|
|
|
+ //Load the existing PDF document
|
|
|
+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument(original);
|
|
|
+
|
|
|
+ //Create a new compression option.
|
|
|
+ PdfCompressionOptions options = new PdfCompressionOptions();
|
|
|
+ //Enable the compress image.
|
|
|
+ options.CompressImages = true;
|
|
|
+ //Set the image quality.
|
|
|
+ options.ImageQuality = 50;
|
|
|
+
|
|
|
+ //Assign the compression option to the document.
|
|
|
+ loadedDocument.CompressionOptions = options;
|
|
|
+
|
|
|
+ //Creating the stream object.
|
|
|
+ using (MemoryStream stream = new MemoryStream())
|
|
|
+ {
|
|
|
+ //Save the document into stream.
|
|
|
+ loadedDocument.Save(stream);
|
|
|
+ return stream.GetBuffer();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public static byte[] ReportToPDF(ReportTemplate template, DataModel data, bool repopulate = true)
|
|
|
{
|
|
|
byte[] result = null;
|
|
|
if (template.IsRDL)
|
|
|
MessageBox.Show("RDL Reports are not supported!");
|
|
|
- // using (var pdf = new MemoryStream())
|
|
|
- // {
|
|
|
- // using (var ms = ReportUtils.SetupReportToStream(template.RDL, data.AsDictionary))
|
|
|
- // {
|
|
|
- // using (ReportWriter reportWriter = new ReportWriter(ms))
|
|
|
- // {
|
|
|
- // reportWriter.ReportProcessingMode = Syncfusion.ReportWriter.ProcessingMode.Local;
|
|
|
- // reportWriter.Save(pdf, WriterFormat.PDF);
|
|
|
- //
|
|
|
- // //String filename = Path.Combine(GetPath(), "report.pdf");
|
|
|
- // //reportWriter.Save(filename, WriterFormat.PDF);
|
|
|
- // //PdfLoadedDocument rpt = new PdfLoadedDocument(filename);
|
|
|
- //
|
|
|
- // PdfLoadedDocument rpt = new PdfLoadedDocument(pdf);
|
|
|
- // PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
|
|
|
- // PdfDocument.Merge(doc, rpt);
|
|
|
- // var msFinal = new MemoryStream();
|
|
|
- // doc.Save(msFinal);
|
|
|
- // result = msFinal.GetBuffer();
|
|
|
- // }
|
|
|
- // }
|
|
|
- // //result = GhostScriptIt(pdf.GetBuffer());
|
|
|
- // //result = pdf.GetBuffer();
|
|
|
- // }
|
|
|
else
|
|
|
using (var report = SetupReport(template, data, repopulate))
|
|
|
{
|
|
|
report.Prepare();
|
|
|
var ms = new MemoryStream();
|
|
|
- report.Export(new PDFExport(), ms);
|
|
|
+ report.Export(new PDFExport() { JpegCompression = true, JpegQuality = 65, Compressed = true }, ms);
|
|
|
result = ms.GetBuffer();
|
|
|
}
|
|
|
|