public static void Execute(IActiveDocument activeDocument, IPublishPdfOptions options) { try { var publisher = new PDFPublisher(); var publisherOptions = publisher.CreateOptionsObject(); publisherOptions.ReconstructHyperlinks = true; if (!options.PrintAll) publisherOptions.PageRange = options.PageRange; if (!options.PrintAll || options.Clean) { publisher.PublishFile(activeDocument.CurrentSnapShot, options.Destination, publisherOptions); } else { publisher.PublishDocument(activeDocument.Instance, options.Destination, publisherOptions); } if (options.PdfFormat) { var password = options.OpenPassword == options.ConfirmOpenPassword ? options.OpenPassword : ""; publisher.SetPDFPermissions(options.Destination, password, options.DisablePrinting, options.DisableModification, options.DisableCopy, options.DisableNotesModification); } else { publisher.ConvertPDFToPDFA(options.Destination); } } catch (COMException e) { // 0x800a1066 & 0x8000FFFF comes back as a HRESULT from Word::Document::PrintOut in the case of cancel being // clicked in the "warn when saveing with track changes dialog" see TFS 7225 if ((uint)e.ErrorCode == (uint)0x800a1066 || ((uint)e.ErrorCode == (uint)0x8000FFFF)) { if (activeDocument.IsFinal) { return; } } throw new Exception("Unable to convert to PDF: " + e.Message); } catch (Exception e) { Logger.LogError(e); throw; } finally { new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications(); } }
public static void Main(string[] args) { // ensure path to file is absolute, not relative string filename = args[0]; if (!Path.IsPathRooted(filename)) filename = Path.Combine(Environment.CurrentDirectory, filename); IPDFPublisher pub = new PDFPublisher(); IPDFPublisherOptions options = pub.CreateOptionsObject(); options.PageRange = "1-3"; options.ReconstructHyperlinks = true; string targetFileName = Path.GetTempFileName(); pub.PublishFile(filename, targetFileName, options); }
public void TestRelativePath3() { string outputDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\output.pdf"); IPDFPublisher p = new PDFPublisher(); p.PublishFile("test.doc", outputDoc); }
private static long PublishFileToPdf(string sourceFile, string sPages = null) { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(sourceFile); FileInfo fi = new FileInfo(testDoc); string copyDoc = Path.Combine(fi.DirectoryName, fi.Name + "copy" + fi.Extension); if (File.Exists(testDoc)) { File.Copy(testDoc, copyDoc); } else { copyDoc = testDoc; } try { string outputDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\output.pdf"); if (File.Exists(outputDoc)) File.Delete(outputDoc); IPDFPublisher p = new PDFPublisher(); p.PublishFile(copyDoc, outputDoc, new PDFPublisherOptions() { PageRange = sPages }); Assert.IsTrue(File.Exists(outputDoc)); long result = new FileInfo(outputDoc).Length; File.Delete(outputDoc); return result; } finally { File.Delete(copyDoc); } }
public void TestRelativePath() { IPDFPublisher p = new PDFPublisher(); p.PublishFile("test.doc", "test.pdf"); }
public void TestApplyPermissions() { string sourceFile = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.pdf"); string tempCopy = Path.GetTempFileName(); File.Copy(sourceFile, tempCopy, true); try { IPDFPublisher p = new PDFPublisher(); p.SetPDFPermissions(tempCopy, "cheesy", true, true, true, true); } finally { File.Delete(tempCopy); } }