PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
open pdf in webform help https://forum.pdfsharp.net/viewtopic.php?f=2&t=2913 |
Page 1 of 1 |
Author: | campagnolo_1 [ Mon Aug 25, 2014 5:24 pm ] |
Post subject: | open pdf in webform help |
Hello everyone, new to the forum and new to pdfsharp. I'm trying to create a C# winform program that will open a PDF from a file location, then redact(*) a portion of the PDF, and finally save the PDF in the same location with a random password encryption. I have found many bits and pieces of code here on the forum and by using google, but the one thing that I still can't figure is how to actually open a PDF using winforms and C#. The issue seems to be that I'm not referencing the correct dll's. I have, for example, this simple code snippet that is supposed to open a file dialog and let me open a file: Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using PdfSharp; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, System.EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*"; dlg.ShowDialog(); this.acroViewer.LoadFile(dlg.FileName); } //this.acroViewer.ShowToolbar = false; } } } But I get an error from VS2010 saying that there is no definition for acroviewer. I loaded the nuget package for PdfSharp and it shows in the references. So what else am I missing? Thanks for the help! Chris (*) I know I'm not really redacting, merely covering things up, but the password protection is sort of a workaround to make it look like it's redacted. ![]() |
Author: | Thomas Hoevel [ Tue Aug 26, 2014 8:00 am ] |
Post subject: | Re: open pdf in webform help |
You have to add something like "private PdfSharp.Viewing.PdfAcroViewer acroViewer;" to your form. You should be able to add the PdfAcroViewer using the Winforms editor. |
Author: | campagnolo_1 [ Tue Aug 26, 2014 1:52 pm ] |
Post subject: | Re: open pdf in webform help |
Thomas, thank you for your reply. I have tried adding Code: using PdfSharp.Viewing; and further on this Code: private PdfSharp.Viewing.PdfAcroViewer acroViewer; . But I get an error saying that the "Type or Namespace Name "Viewing" does not exist in the Namespace'PdfSharp'. So I'm not sure if I have the wrong package or if something has changed since the code I found was written and the code needs to be changed. |
Author: | Thomas Hoevel [ Tue Aug 26, 2014 2:58 pm ] |
Post subject: | Re: open pdf in webform help |
It seems that version 1.32 does not include the viewer. Go to http://pdfsharp.codeplex.com/releases/view/37054 and download PDFSharp-MigraDocFoundation-1_31.zip After unzipping, you'll find the project in PDFsharp\dev\PdfViewer.Demo The solution PDFsharp-VS2008.sln is in the parent directory. Newer VS versions should be able to convert it. |
Author: | campagnolo_1 [ Wed Aug 27, 2014 2:12 pm ] |
Post subject: | Re: open pdf in webform help |
Thomas, thanks for the link. I downloaded 1.31 but when I try to open and build the PdfSharp-VS2008 i get multiple errors. I'm not sure if I'm doing everything right, so let me just tell you the steps: 1. Open the PdfSharp-VS2008 and converting it (that works fine with only a handful of warnings, no errors) 2. Click on the Solution and then click "Build" 3. I get multiple errors and warnings:
Error 2 Warning as Error: 'System.Drawing.FontFamily.GetFamilies(System.Drawing.Graphics)' is obsolete: 'Do not use method GetFamilies, use property Families instead' C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\PdfSharp.Drawing\XFontFamily.cs 267 18 PdfSharp Error 3 Metadata file 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll' could not be found PdfSharp.Charting Error 4 Metadata file 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll' could not be found PdfSharp.Ghostscript Error 5 Metadata file 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll' could not be found PrivateFonts Error 6 Could not load referenced assembly "C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll". Caught a FileNotFoundException saying "Could not load file or assembly 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll' or one of its dependencies. The system cannot find the file specified.". C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\dev\PDFsharp.Explorer\ResGen PdfSharp.Explorer Error 7 Could not load referenced assembly "C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll". Caught a FileNotFoundException saying "Could not load file or assembly 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll' or one of its dependencies. The system cannot find the file specified.". C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\dev\XGraphicsLab\ResGen XGraphicsLab Error 8 Could not load referenced assembly "C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp.Charting\bin\Debug\PdfSharp.Charting.dll". Caught a FileNotFoundException saying "Could not load file or assembly 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp.Charting\bin\Debug\PdfSharp.Charting.dll' or one of its dependencies. The system cannot find the file specified.". C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\dev\PdfSharp.Charting.Demo\ResGen PdfSharp.Charting.Demo Error 9 Could not load referenced assembly "C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll". Caught a FileNotFoundException saying "Could not load file or assembly 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll' or one of its dependencies. The system cannot find the file specified.". C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\dev\PdfSharp.Ghostscript.Demo\ResGen UseGhostscript Error 10 Could not load referenced assembly "C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll". Caught a FileNotFoundException saying "Could not load file or assembly 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll' or one of its dependencies. The system cannot find the file specified.". C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp.AcroPdfLib\ResGen PdfSharp.AcroPdfLib Error 11 System.ApplicationException - Unable to located specified reference: 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll' C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\dev\PdfViewer.Demo\TlbImp PdfViewer.Demo Warning 12 Cannot find wrapper assembly for type library "AcroPDFLib". Verify that (1) the COM component is registered correctly and (2) your target platform is the same as the bitness of the COM component. For example, if the COM component is 32-bit, your target platform must not be 64-bit. PdfViewer.Demo Error 13 Unable to locate referenced assembly: 'C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\dev\PdfViewer.Demo\obj\Debug\Interop.AcroPDFLib.dll' C:\Users\KokatatTest\Documents\Visual Studio 2010\Projects\PdfSharp\PDFsharp\dev\PdfViewer.Demo\AXIMP PdfViewer.Demo Warning 14 Cannot find wrapper assembly for type library "AxAcroPDFLib". Verify that (1) the COM component is registered correctly and (2) your target platform is the same as the bitness of the COM component. For example, if the COM component is 32-bit, your target platform must not be 64-bit. PdfViewer.Demo When I open the PdfViewer.Demo I get the following errors:
Warning 2 The referenced component 'PdfSharp.AcroPdfLib' could not be found. Somehow I feel like I'm doing something fundamentally wrong, i.e. I'm not installing/using the package correctly. Any ideas? Sorry for being a pain, Chris |
Author: | Thomas Hoevel [ Wed Aug 27, 2014 2:29 pm ] |
Post subject: | Re: open pdf in webform help |
Compile the project, open the Output window and search for ": error". Address this error and compile again. Probably you just have to disable the "Treat warnings as errors" option in the project settings. "Error 2 Warning as Error" suggests something like that. |
Author: | campagnolo_1 [ Thu Aug 28, 2014 1:56 pm ] |
Post subject: | Re: open pdf in webform help |
Thomas, I'm not sure what I did differently today than I did yesterday, but I'm happy to report that it works now! Thank you for helping me out and I'm sure as my project goes along I will have many more questions. Cheers, Chris |
Author: | Thomas Hoevel [ Thu Aug 28, 2014 2:03 pm ] |
Post subject: | Re: open pdf in webform help |
campagnolo_1 wrote: I'm not sure what I did differently today than I did yesterday, but I'm happy to report that it works now! Maybe you switched from Release to Debug.Remember the tip from my last post when you switch to Release again ... |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |