diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2022-05-18 19:49:41 +0300 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2022-05-18 19:49:41 +0300 |
| commit | 56e222adc848ccc223e6b1065d311ced5c82f34c (patch) | |
| tree | 3cdbb4a6d3c2eda30c22a4514779af2e965102f1 /Software/Visual_Studio/Tango.PDF | |
| parent | baa65cb88df619c3df68bdf91e0e0476ca614998 (diff) | |
| download | Tango-56e222adc848ccc223e6b1065d311ced5c82f34c.tar.gz Tango-56e222adc848ccc223e6b1065d311ced5c82f34c.zip | |
Vector Fine Tuning.
Diffstat (limited to 'Software/Visual_Studio/Tango.PDF')
| -rw-r--r-- | Software/Visual_Studio/Tango.PDF/PdfWpfWriter.cs | 118 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.PDF/Properties/AssemblyInfo.cs | 36 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.PDF/Tango.PDF.csproj | 67 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.PDF/packages.config | 5 |
4 files changed, 226 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.PDF/PdfWpfWriter.cs b/Software/Visual_Studio/Tango.PDF/PdfWpfWriter.cs new file mode 100644 index 000000000..179b3ada0 --- /dev/null +++ b/Software/Visual_Studio/Tango.PDF/PdfWpfWriter.cs @@ -0,0 +1,118 @@ +using PdfSharp; +using PdfSharp.Drawing; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Packaging; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Threading; +using System.Windows.Xps; +using System.Windows.Xps.Packaging; + +namespace Tango.PDF +{ + public class PdfWpfWriter + { + private List<FrameworkElement> _elements; + + public PdfWpfWriter() + { + _elements = new List<FrameworkElement>(); + } + + public void AddElement(FrameworkElement element) + { + _elements.Add(element); + } + + public void RemoveElement(FrameworkElement element) + { + _elements.Remove(element); + } + + public Size GetA4Size() + { + XSize a4Size = PageSizeConverter.ToSize(PageSize.A4); + return new Size(a4Size.Width, a4Size.Height); + } + + public void Save(String filePath) + { + using (MemoryStream lMemoryStream = new MemoryStream()) + { + Package package = Package.Open(lMemoryStream, FileMode.Create); + XpsDocument doc = new XpsDocument(package); + XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc); + + List<StackPanel> stacks = new List<StackPanel>(); + + StackPanel currentStack = new StackPanel(); + stacks.Add(currentStack); + + XSize a4Size = PageSizeConverter.ToSize(PageSize.A4); + + foreach (var element in _elements.ToList()) + { + //element.Width = a4Size.Width * 0.80; + currentStack.Children.Add(element); + + currentStack.Measure(new Size(Double.MaxValue, Double.MaxValue)); + Size visualSize = currentStack.DesiredSize; + currentStack.Arrange(new Rect(new Point(0, 0), visualSize)); + currentStack.UpdateLayout(); + + if (visualSize.Height > a4Size.Height) + { + currentStack.Children.Remove(element); + currentStack.UpdateLayout(); + currentStack.InvalidateVisual(); + + currentStack = new StackPanel(); + currentStack.Children.Add(element); + stacks.Add(currentStack); + } + } + + Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { })).Wait(); + Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => { })).Wait(); + + FixedDocument fixedDoc = new FixedDocument(); + + foreach (var stack in stacks) + { + PageContent pageContent = new PageContent(); + FixedPage fixedPage = new FixedPage(); + fixedPage.Height = a4Size.Height; + fixedPage.Width = a4Size.Width; + + fixedPage.Children.Add(stack); + ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); + fixedDoc.Pages.Add(pageContent); + } + + writer.Write(fixedDoc); + doc.Close(); + package.Close(); + + MemoryStream outStream = new MemoryStream(); + PdfSharp.Xps.XpsConverter.Convert(lMemoryStream, outStream, true); + + File.WriteAllBytes(filePath, outStream.ToArray()); + + lMemoryStream.Dispose(); + outStream.Dispose(); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.PDF/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Tango.PDF/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..941147f2e --- /dev/null +++ b/Software/Visual_Studio/Tango.PDF/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.PDF")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.PDF")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("84fb2b51-213e-4602-a5db-fa97d8ae907a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/Tango.PDF/Tango.PDF.csproj b/Software/Visual_Studio/Tango.PDF/Tango.PDF.csproj new file mode 100644 index 000000000..47ddba495 --- /dev/null +++ b/Software/Visual_Studio/Tango.PDF/Tango.PDF.csproj @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{84FB2B51-213E-4602-A5DB-FA97D8AE907A}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Tango.PDF</RootNamespace> + <AssemblyName>Tango.PDF</AssemblyName> + <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <Deterministic>true</Deterministic> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + </PropertyGroup> + <ItemGroup> + <Reference Include="HiraokaHyperTools.PdfSharp-WPF, Version=1.31.6209.0, Culture=neutral, PublicKeyToken=f94615aa0424f9eb, processorArchitecture=MSIL"> + <HintPath>..\packages\kenjiuno.PdfSharp-WPF.1.31.6209\lib\net40\HiraokaHyperTools.PdfSharp-WPF.dll</HintPath> + </Reference> + <Reference Include="HiraokaHyperTools.PdfSharp.Xps, Version=1.1.10.0, Culture=neutral, PublicKeyToken=f94615aa0424f9eb, processorArchitecture=MSIL"> + <HintPath>..\packages\kenjiuno.PdfSharp.Xps.1.1.10\lib\net40\HiraokaHyperTools.PdfSharp.Xps.dll</HintPath> + </Reference> + <Reference Include="PresentationCore" /> + <Reference Include="PresentationFramework" /> + <Reference Include="ReachFramework" /> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Drawing" /> + <Reference Include="System.Printing" /> + <Reference Include="System.Xaml" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + <Reference Include="WindowsBase" /> + </ItemGroup> + <ItemGroup> + <Compile Include="PdfWpfWriter.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.PDF/packages.config b/Software/Visual_Studio/Tango.PDF/packages.config new file mode 100644 index 000000000..77755e1a5 --- /dev/null +++ b/Software/Visual_Studio/Tango.PDF/packages.config @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="kenjiuno.PdfSharp.Xps" version="1.1.10" targetFramework="net461" /> + <package id="kenjiuno.PdfSharp-WPF" version="1.31.6209" targetFramework="net461" /> +</packages>
\ No newline at end of file |
