PDF viewer hinzugefügt

Die dateien können nun als PDF und oder als Doc gespeichert werden,  man kann nach den erzeugen, denn PDF dann anzeigen lassen
This commit is contained in:
Husky
2018-07-14 14:34:19 +02:00
parent 30ab917e48
commit 2ee98ea823
8 changed files with 280 additions and 15 deletions

View File

@@ -1,11 +1,14 @@
using SanShared;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocToPDFConverter;
using Syncfusion.Pdf;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -24,7 +27,7 @@ namespace BerichtGen
/// <param name="daten">Inhalt vom Dokument </param>
/// <param name="erzeugeDoc">Ein doc datei soll erzeugt werden</param>
/// <param name="erzeugePDF">Ein Pdf datei soll erzeugt werden</param>
public void Erzeuge(string source, string savepath, Hashtable daten,List<BilderObject> bilderObjects,DataTable tableContents, bool erzeugeDOC = false , bool erzeugePDF = true)
public void Erzeuge(string source, string savepath,string filename, Hashtable daten,List<BilderObject> bilderObjects,DataTable tableContents, bool erzeugeDOC = false , bool erzeugePDF = true)
{
if (bilderObjects != null)
{
@@ -65,19 +68,39 @@ namespace BerichtGen
}
//wordDocument.MailMerge.Execute(fieldnames, fieldvalues);
wordDocument.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MailMerge_MergeImageField);
//string[] fieldNames = new string[] { "UVImage" };
//string[] fieldValues = new string[] { "test.png" };
if (tableContents != null)
wordDocument.MailMerge.ExecuteGroup(tableContents);
wordDocument.MailMerge.Execute(fieldnames, fieldvalues);
wordDocument.Save("test.docx", Syncfusion.DocIO.FormatType.Docx);
//wordDocument.Close();
//wordDocument.MailMerge.ExecuteGroup()
if(erzeugeDOC)
wordDocument.Save(Path.Combine(savepath,string.Format("{0}.doc",filename)), Syncfusion.DocIO.FormatType.Doc);
if (erzeugePDF)
{
string speichername = Path.Combine(savepath, string.Format("{0}.pdf", filename));
DocToPDFConverter docToPDFConverter = new DocToPDFConverter();
PdfDocument pdf = docToPDFConverter.ConvertToPDF(wordDocument);
try
{
pdf.Save(speichername);
}
catch
{
}
finally
{
pdf.Dispose();
}
}
}
private readonly double _cmPixel = 0.393700787;
private readonly int _dpi = 120;

View File

@@ -76,12 +76,21 @@
<Compile Include="FrmOptions.Designer.cs">
<DependentUpon>FrmOptions.cs</DependentUpon>
</Compile>
<Compile Include="FrmPDFViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmPDFViewer.Designer.cs">
<DependentUpon>FrmPDFViewer.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FrmOptions.resx">
<DependentUpon>FrmOptions.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmPDFViewer.resx">
<DependentUpon>FrmPDFViewer.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SanShared\SanShared.csproj">

View File

@@ -22,10 +22,11 @@ namespace BerichtGen
string vorlage;
string speicherpfad;
string source;
string filename;
List<BilderObject> bilderObjects;
DataTable tableContent = null;
public FrmOptions(string firma, string vorlage, string speicherpfad, Hashtable grunddaten, List<BilderObject> bilderObjects, DataTable tableContent = null)
public FrmOptions(string firma, string vorlage, string speicherpfad,string filename, Hashtable grunddaten, List<BilderObject> bilderObjects, DataTable tableContent = null)
{
InitializeComponent();
@@ -36,13 +37,13 @@ namespace BerichtGen
this.bilderObjects = bilderObjects;
this.tableContent = tableContent;
this.source = Path.Combine("documents", firma, vorlage);
this.filename = filename;
}
void Gen()
{
Bericht bericht = new Bericht();
bericht.Erzeuge(source, speicherpfad, grundDaten, bilderObjects, tableContent);
bericht.Erzeuge(source, speicherpfad,filename, grundDaten, bilderObjects, tableContent,cb_doc.Checked,cb_pdf.Checked);
}
private void btn_start_Click(object sender, EventArgs e)
@@ -56,9 +57,11 @@ namespace BerichtGen
}
if (rb_yes.Checked)
if (rb_yes.Checked && cb_pdf.Checked)
{
string pfad = Path.Combine(speicherpfad, string.Format("{0}.pdf", filename));
FrmPDFViewer frmPDFViewer = new FrmPDFViewer(pfad);
frmPDFViewer.ShowDialog();
}
this.Close();

74
BerichtGen/FrmPDFViewer.Designer.cs generated Normal file
View File

@@ -0,0 +1,74 @@
namespace BerichtGen
{
partial class FrmPDFViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
Syncfusion.Windows.PdfViewer.PdfViewerPrinterSettings pdfViewerPrinterSettings1 = new Syncfusion.Windows.PdfViewer.PdfViewerPrinterSettings();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmPDFViewer));
this.pdfViewerControl = new Syncfusion.Windows.Forms.PdfViewer.PdfViewerControl();
this.SuspendLayout();
//
// pdfViewerControl
//
this.pdfViewerControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.pdfViewerControl.EnableNotificationBar = true;
this.pdfViewerControl.IsBookmarkEnabled = true;
this.pdfViewerControl.Location = new System.Drawing.Point(0, 0);
this.pdfViewerControl.Name = "pdfViewerControl";
this.pdfViewerControl.PageBorderThickness = 1;
pdfViewerPrinterSettings1.PrintLocation = ((System.Drawing.PointF)(resources.GetObject("pdfViewerPrinterSettings1.PrintLocation")));
this.pdfViewerControl.PrinterSettings = pdfViewerPrinterSettings1;
this.pdfViewerControl.ScrollDisplacementValue = 0;
this.pdfViewerControl.ShowHorizontalScrollBar = true;
this.pdfViewerControl.ShowToolBar = true;
this.pdfViewerControl.ShowVerticalScrollBar = true;
this.pdfViewerControl.Size = new System.Drawing.Size(638, 749);
this.pdfViewerControl.TabIndex = 0;
this.pdfViewerControl.Text = "pdfViewerControl1";
this.pdfViewerControl.ZoomMode = Syncfusion.Windows.Forms.PdfViewer.ZoomMode.FitPage;
//
// FrmPDFViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.ClientSize = new System.Drawing.Size(638, 749);
this.Controls.Add(this.pdfViewerControl);
this.Name = "FrmPDFViewer";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FrmPDFViewer";
this.Load += new System.EventHandler(this.FrmPDFViewer_Load);
this.ResumeLayout(false);
}
#endregion
private Syncfusion.Windows.Forms.PdfViewer.PdfViewerControl pdfViewerControl;
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BerichtGen
{
public partial class FrmPDFViewer : Form
{
string pfad;
public FrmPDFViewer(string pfad)
{
InitializeComponent();
this.pfad = pfad;
}
private void FrmPDFViewer_Load(object sender, EventArgs e)
{
pdfViewerControl.Load(pfad);
}
}
}

View File

@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="pdfViewerPrinterSettings1.PrintLocation" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBDdWx0
dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJh
d2luZy5Qb2ludEYCAAAAAXgBeQAACwsCAAAAAAAAAAAAAAAL
</value>
</data>
</root>

View File

@@ -212,7 +212,7 @@ namespace SanSystem
Kommentar = "TestBild",
Path = @"C:\Users\Damian\Desktop\SanVerwaltung\SanSystem\bin\Debug\projekte\18-850\SW01-SW02\Schachtanbindung\4d0a1627-bd51-48d6-a27e-a4c6691b02d2.jpg"
});
BerichtGen.FrmOptions options = new BerichtGen.FrmOptions("", "", "", grunddaten,bilderO);
BerichtGen.FrmOptions options = new BerichtGen.FrmOptions("", "", "","", grunddaten,bilderO);
options.ShowDialog();
}
@@ -314,7 +314,9 @@ namespace SanSystem
private void btn_create_protokol_Click(object sender, EventArgs e)
{
Hashtable hashtable = inliner.MakeProtokoll(destinationPath);
BerichtGen.FrmOptions options = new BerichtGen.FrmOptions("JUME", "liner_einbau.docx", "./", hashtable, new List<BilderObject>());
DirectoryInfo directory = Directory.GetParent(destinationPath);
string speicherpfad = directory.FullName;
BerichtGen.FrmOptions options = new BerichtGen.FrmOptions("JUME", "liner_einbau.docx", speicherpfad,inliner.Inspektionsobjekt.Objektbezeichnung, hashtable, new List<BilderObject>());
options.ShowDialog();
}
}

View File

@@ -270,7 +270,7 @@ namespace SanSystem
dr["bemerkung"] = obj.Bemerkung;
linereintraege.Rows.Add(dr);
}
BerichtGen.FrmOptions options = new BerichtGen.FrmOptions("JUME", "KalibrierungAuflistung.docx", "", grundDaten, null, linereintraege);
BerichtGen.FrmOptions options = new BerichtGen.FrmOptions("JUME", "KalibrierungAuflistung.docx", "","", grundDaten, null, linereintraege);
options.ShowDialog();
}