I need to convert a bunch PDFs to XPS documents programmatically (in C#). Therefore, I tried to call several command line tools:
AcroRd32.exe (Adobe Reader)
SumatraPDF.exe (neat portable tool)
PDF2Printer for Windows 10
and many, many others.
However, none of them seems to support functionallity to specify a filename for the generated XPS, which causes the "Save-Dialog" to pop-up on call. I am looking for a complete silent way to convert a PDF to XPS without any user interaction. Furthermore, I wish to use only tools that are free for commercial use (without any AGPL licensing). Any workarounds for this issue?
The following lib supports to convert pdf to xps and specify file name for generated xps file but with limitations: http://freepdf.codeplex.com
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("FileName.pdf");
doc.SaveToFile("FileName.xps", FileFormat.XPS);
Related
I was unable to find a free library which can directly convert PCL file to PDF file, i had a thought of reading the PCL file into FileStream and saving it to a PDF document using PDF Sharp.
I tried the following code, but it gives me a blank PDF Document.
Can someone let me know what or where i'm doing it incorrectly?
private void pdfSharpPclToPDF(string localPCLPath)
{
using(FileStream fleStream = new FileStream(localPCLPath, FileMode.Open))
{
using (PdfDocument newPDF = new PdfDocument(fleStream))
{
PdfPage pdfPage = new PdfPage(newPDF);
newPDF.Pages.Add(pdfPage);
newPDF.Save("D:\\Research\\PDF_Files\\output.pdf");
}
}
}
It would also help if someone could suggest any other open source library that can do the job for me.
PDFsharp does not use the filestream you create. If you invoke Save() without filename, PDFsharp will save the PDF document to the stream. If you invoke Save(<filename>) the document will be saved in that file.
PDFsharp cannot read PCL files. You are trying something that cannot work with PDFsharp.
Most Applications will usually include some way to export content as a printer output. The higher end various output formats are generically referred to as PDL (Page Description Language) and historically were stored as filename.prn without distinguishing content.
The contents of a PRN could traditionally be Esc code as used by Epson , PostScript Programs or PCL (Printer Control Language) plus many others and nowadays we often include the formerly dumber PDF which is accepted by high end printers.
So PDFsharp can Export to PCL via a driver but is not designed to Import it for conversion into PDF output.
One application that can convert bidirectionally between PDL devices is Artifex GhostPDL (it does NOT Import Epson Esc Code but can export Epson code). GhostScript is Open Source, as you request, but is (AGPL) commercial licensed. However it is the most capable with a few decades of history.
I'm currently working with Microsoft.Office.Interop.Word to open a .docx file and convert to PDF. In order to do that, I'm doing this :
Opening the .docx file with Microsoft.Office.Interop.Word.Documents.Open()
Exporting this document as a PDF with Microsoft.Office.Interop.Word._Document.ExportAsFixedFormat()
I used this method ("Call the Protect method of the Microsoft.Office.Interop.Word.Document that you want to protect") : https://msdn.microsoft.com/library/ms178793(v=vs.110).aspx
I have my PDF file, but I can open it in Microsoft Word and edit it... I don't want this PDF to be editable and I must use Word automation to make the PDF.
My question is in the title:
How to disable Word 2013 PDF edition?
It's not possible to change the way Word converts to PDF. There are some options that can be set, using the method you use, but the basic code can't be changed. If you want special things it might be worthwhile to invest in Adobe Acrobat and/Or its API. Since PDF is Adobe's file format its product will have all the special things - it doesn't license some of these things to third parties (such as Microsoft).
In my program I generate some reports in FlowDocument and display it with DocumentViewer control.
Now I need to add more export opportunities. I use iTextSharp to export in PDF, and I can save to XPS natively. Can I save a document directly to any office formats, DOC or XLS. Or maybe someone knows of a good library for converting from PDF / XPS in DOC or XLS?
I found a solution. As I can't export to Doc from WPF automatically, I reproduced my page layout with DocX Library. This is really awesome and simple library that don't required MSOffice installed to create Word 2007/2010 files.
I'm not sure if you're looking for an answer, so I'll be brief. You can use the Microsoft Interop assemblies to create Word documents. It's no menial task, but in my opinion, it's easier than using iTextSharp. They come with Visual Studio.
To create XPS documents, you'll need to generate FixedDocument objects from your FlowDocument, but from there, it's only a few lines of code. Eric Sink has a nice article that you can find here. This is also mentioned in this question posted here.
I need to convert PDF files into .doc files using C#. The computer has no file system though it doesn't have Office installed. Any good ideas how I can approach this? I did some research and most of people use the interop services.
You need to understand that PDF is not really implemented as a single document format.
If your PDF docs are created by rendering text to a PDF file, then direct PDF conversion is not only possible, but can be very good (reliable).
If the source of your PDF is either a scanner or fax (essentially a scanner...) then what you have is a document with an "picture" of text. This scenario is more difficult to deal with. If you open up the markup for this there is no 'text' to be converted. In this situation you have to deal with some manner of OCR (optical character recognition) which is less reliable due to a variety of issues.
If you have the option of intercepting the data before it is rendered to PDF (say like in SSRS or Crystal) then it would be better for you to bypass the PDF stage and move your data to a Word document.
If you are constrained to receiving faxes and then needing to interpret their content, prepare for OCR hell. It has been a while since I was there, so I hope that it has gotten better.
Even with out office installed on your machine, you have access (with Visual Studios) to the Office developer toolkit which will allow you build documents to be distributed in the Word formats.(.doc/.docx).
An option/idea may be to convert the PDF to Html, which can be opened in Word?
use aspose pdf kit to conver pdf to text and then text to doc using filestream or aspose doc
Are there any free tools that I can use to convert a PDF document into an XPS document? Although a nice programmatic API would be nice, I'm not opposed to shelling out to a command line tool to do the conversion.
Thanks!
AbcPdf version 7 includes this funcationality, if you link back to their site you can have a free license key. Utilize the save method to accomplish PDF - XPS conversions.
XPS is exported only if the supplied path ends with ".xps", and it requires the .NET Framework 3.0. XPS is supported via Doc.SaveOptions.FileExtension of the Save method when saving to a stream. Set this property to either ".xps" or "xps" otherwise a conventional PDF output will be generated. XPS streams must have FileAccess.ReadWrite and not simply FileAccess.Write otherwise the operation will fail.
virtual void Save(Stream stream)