public static void Run() { //ExStart:DigitallySignedPdf // The path to the documents directory. string dataDir = RunExamples.GetDataDir_LoadingAndSaving(); // Create a simple document from scratch. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Test Signed PDF."); // Load the certificate from disk. // The other constructor overloads can be used to load certificates from different locations. X509Certificate2 cert = new X509Certificate2( dataDir + "signature.pfx", "signature"); // Pass the certificate and details to the save options class to sign with. PdfSaveOptions options = new PdfSaveOptions(); options.DigitalSignatureDetails = new PdfDigitalSignatureDetails( cert, "Test Signing", "Aspose Office", DateTime.Now); dataDir = dataDir + "Document.Signed_out_.pdf"; // Save the document as PDF with the digital signature set. doc.Save(dataDir, options); //ExEnd:DigitallySignedPdf Console.WriteLine("\nDigitally signed PDF file created successfully.\nFile saved at " + dataDir); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Open an Excel file Workbook workbook = new Workbook(dataDir+ "input.xlsx"); //Instantiate PDFSaveOptions to manage security attributes PdfSaveOptions saveOption = new PdfSaveOptions(); saveOption.SecurityOptions = new Aspose.Cells.Rendering.PdfSecurity.PdfSecurityOptions(); //Set the user password saveOption.SecurityOptions.UserPassword = "******"; //Set the owner password saveOption.SecurityOptions.OwnerPassword = "******"; //Disable extracting content permission saveOption.SecurityOptions.ExtractContentPermission = false; //Disable print permission saveOption.SecurityOptions.PrintPermission = false; //Save the PDF document with encrypted settings workbook.Save(dataDir+ "securepdf_test.pdf", saveOption); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // ExStart:RenderResourceUsageView // Create project instance Project project1 = new Project(dataDir + "ResourceUsageView.mpp"); // Define the SaveOptions with required TimeScale settings as Days SaveOptions options = new PdfSaveOptions(); options.Timescale = Timescale.Days; // Set the Presentation format to ResourceUsage options.PresentationFormat = PresentationFormat.ResourceUsage; // Save the Project string outputFile = "result_ResourceUsageView_days_out.pdf"; project1.Save(dataDir + outputFile, options); // Set the Tiemscale settings to ThirdsOfMonths and save the Project options.Timescale = Timescale.ThirdsOfMonths; outputFile = "result_ResourceUsageView_thirdsOfMonths_out.pdf"; project1.Save(dataDir + outputFile, options); // Set the Timescale settings to Months and save the Project options.Timescale = Timescale.Months; outputFile = "result_ResourceUsageView_months_out.pdf"; project1.Save(dataDir + outputFile, options); // ExEnd:RenderResourceUsageView }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // ExStart:AlignCellContents Project project = new Project(dataDir + "Project2.mpp"); SaveOptions options = new PdfSaveOptions(); options.Timescale = Timescale.Months; options.View = ProjectView.GetDefaultGanttChartView(); GanttChartColumn column1 = options.View.Columns[2] as GanttChartColumn; column1.StringAlignment = StringAlignment.Center; column1 = options.View.Columns[3] as GanttChartColumn; column1.StringAlignment = StringAlignment.Far; column1 = options.View.Columns[4] as GanttChartColumn; column1.StringAlignment = StringAlignment.Far; project.Save(dataDir + "AlignCellContents_GanttChart_out.pdf", options); options.PresentationFormat = PresentationFormat.ResourceSheet; options.View = ProjectView.GetDefaultResourceSheetView(); ResourceViewColumn column2 = options.View.Columns[2] as ResourceViewColumn; column2.StringAlignment = StringAlignment.Center; column2 = options.View.Columns[3] as ResourceViewColumn; column2.StringAlignment = StringAlignment.Far; column2 = options.View.Columns[4] as ResourceViewColumn; column2.StringAlignment = StringAlignment.Far; project.Save(dataDir + "AlignCellContents_ResourceSheet_out.pdf", options); // ExEnd:AlignCellContents }
public static void Run() { // ExStart:CreateBookmark // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithBookmarks(); Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.StartBookmark("My Bookmark"); builder.Writeln("Text inside a bookmark."); builder.StartBookmark("Nested Bookmark"); builder.Writeln("Text inside a NestedBookmark."); builder.EndBookmark("Nested Bookmark"); builder.Writeln("Text after Nested Bookmark."); builder.EndBookmark("My Bookmark"); PdfSaveOptions options = new PdfSaveOptions(); options.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1); options.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2); dataDir = dataDir + "Create.Bookmark_out.pdf"; doc.Save(dataDir, options); // ExEnd:CreateBookmark Console.WriteLine("\nBookmark created successfully.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Open an Excel file Workbook workbook = new Workbook(dataDir+ "input.xlsx"); // Instantiate PDFSaveOptions to manage security attributes PdfSaveOptions saveOption = new PdfSaveOptions(); saveOption.SecurityOptions = new Aspose.Cells.Rendering.PdfSecurity.PdfSecurityOptions(); // Set the user password saveOption.SecurityOptions.UserPassword = "******"; // Set the owner password saveOption.SecurityOptions.OwnerPassword = "******"; // Disable extracting content permission saveOption.SecurityOptions.ExtractContentPermission = false; // Disable print permission saveOption.SecurityOptions.PrintPermission = false; // Save the PDF document with encrypted settings workbook.Save(dataDir+ "securepdf_test.out.pdf", saveOption); // ExEnd:1 }
public void CheckThatAllMethodsArePresent() { HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions(); htmlFixedSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback(); ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png); imageSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback(); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback(); PsSaveOptions psSaveOptions = new PsSaveOptions(); psSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback(); SvgSaveOptions svgSaveOptions = new SvgSaveOptions(); svgSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback(); SwfSaveOptions swfSaveOptions = new SwfSaveOptions(); swfSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback(); XamlFixedSaveOptions xamlFixedSaveOptions = new XamlFixedSaveOptions(); xamlFixedSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback(); XpsSaveOptions xpsSaveOptions = new XpsSaveOptions(); xpsSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback(); }
public static void Run() { try { // ExStart:ExportOfHiddenVisioPagesToPDF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Intro(); // Load an existing Visio Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); // Get a particular page Page page = diagram.Pages.GetPage("Flow 2"); // Set Visio page visiblity page.PageSheet.PageProps.UIVisibility.Value = BOOL.True; // Initialize PDF save options PdfSaveOptions options = new PdfSaveOptions(); // Set export option of hidden Visio pages options.ExportHiddenPage = false; // Save the Visio diagram diagram.Save(dataDir + "ExportOfHiddenVisioPagesToPDF_out.pdf", options); // ExEnd:ExportOfHiddenVisioPagesToPDF } catch (System.Exception ex) { System.Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); } }
static void Main() { Workbook workbook = new Workbook("F:\\AllExamples\\Aspose.Cells\\net\\TechnicalArticles\\Aspose.CellsGeneral\\GetWarningsForFontSubstitution\\Data\\source.xlsx"); PdfSaveOptions options = new PdfSaveOptions(); options.WarningCallback = new GetWarningsForFontSubstitution(); workbook.Save("F:\\AllExamples\\Aspose.Cells\\net\\TechnicalArticles\\Aspose.CellsGeneral\\GetWarningsForFontSubstitution\\Data\\output.pdf", options); }
public void DrawingMl() { Document doc = DocumentHelper.CreateDocumentFillWithDummyText(); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.DmlRenderingMode = DmlRenderingMode.DrawingML; doc.Save(MyDir + @"\Artifacts\DrawingMl.pdf", pdfSaveOptions); }
public void DrawingMl() { Document doc = DocumentHelper.CreateDocumentFillWithDummyText(); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.DmlRenderingMode = DmlRenderingMode.DrawingML; doc.Save(TestDir + "DrawingMl OUT.pdf", pdfSaveOptions); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Workbook workbook = new Workbook(dataDir + "source.xlsx"); PdfSaveOptions options = new PdfSaveOptions(); options.WarningCallback = new GetWarningsForFontSubstitution(); dataDir = dataDir + "output_out.pdf"; workbook.Save(dataDir, options); }
public static void Main() { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Create and initialize an instance of Workbook Workbook book = new Workbook(dataDir + "TestBook.xlsx"); //Create and initialize an instance of PdfSaveOptions PdfSaveOptions saveOptions = new PdfSaveOptions(SaveFormat.Pdf); //Set AllColumnsInOnePagePerSheet to true saveOptions.AllColumnsInOnePagePerSheet = true; //Save Workbook to PDF fromart by passing the object of PdfSaveOptions book.Save(dataDir+ "output.out.pdf", saveOptions); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Create and initialize an instance of Workbook Workbook book = new Workbook(dataDir + "TestBook.xlsx"); //Create and initialize an instance of PdfSaveOptions PdfSaveOptions saveOptions = new PdfSaveOptions(SaveFormat.Pdf); //Set AllColumnsInOnePagePerSheet to true saveOptions.AllColumnsInOnePagePerSheet = true; //Save Workbook to PDF fromart by passing the object of PdfSaveOptions book.Save(dataDir+ "output.pdf", saveOptions); }
public static void Run() { // ExStart:RenderTaskSheetView // Create project instance string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); Project project1 = new Project(dataDir + "TaskSheetView.mpp"); // Set presentation format Task Sheet and save project as PDF SaveOptions options = new PdfSaveOptions(); options.PresentationFormat = PresentationFormat.TaskSheet; project1.Save(dataDir + "TaskSheetView_out.pdf", options); // ExEnd:RenderTaskSheetView }
private static void EmbeddSubsetFonts(Document doc, string dataDir) { // ExStart:EmbeddSubsetFonts // To subset fonts in the output PDF document, simply create new PdfSaveOptions and set EmbedFullFonts to false. PdfSaveOptions options = new PdfSaveOptions(); options.EmbedFullFonts = false; dataDir = dataDir + "Rendering.SubsetFonts_out.pdf"; // The output PDF will contain subsets of the fonts in the document. Only the glyphs used // In the document are included in the PDF fonts. doc.Save(dataDir, options); // ExEnd:EmbeddSubsetFonts Console.WriteLine("\nSubset Fonts embedded successfully.\nFile saved at " + dataDir); }
private static void SkipEmbeddedArialAndTimesRomanFonts(Document doc, string dataDir) { // ExStart:SkipEmbeddedArialAndTimesRomanFonts // To subset fonts in the output PDF document, simply create new PdfSaveOptions and set EmbedFullFonts to false. // To disable embedding standard windows font use the PdfSaveOptions and set the EmbedStandardWindowsFonts property to false. PdfSaveOptions options = new PdfSaveOptions(); options.FontEmbeddingMode = PdfFontEmbeddingMode.EmbedAll; dataDir = dataDir + "Rendering.DisableEmbedWindowsFonts_out.pdf"; // The output PDF will be saved without embedding standard windows fonts. doc.Save(dataDir); // ExEnd:SkipEmbeddedArialAndTimesRomanFonts Console.WriteLine("\nEmbedded arial and times new roman fonts are skipped successfully.\nFile saved at " + dataDir); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Initialize a new Workbook //Open an Excel file Workbook workbook = new Workbook(dataDir+ "input.xlsx"); //Implement one page per worksheet option PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.OnePagePerSheet = true; //Save the PDF file workbook.Save(dataDir+ "OutputFile.pdf", pdfSaveOptions); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // ExStart:SaveToMultiplePDFFiles Project project = new Project(dataDir + "Software Development Plan.mpp"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.SaveToSeparateFiles = true; saveOptions.Pages = new List<int>(); saveOptions.Pages.Add(1); saveOptions.Pages.Add(4); project.Save(dataDir + "SaveToMultiplePDFFiles_out.pdf", saveOptions); // ExEnd:SaveToMultiplePDFFiles }
public void CreateMissingOutlineLevels() { Document doc = DocumentHelper.CreateDocumentFillWithDummyText(); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); //Set maximum value of levels of headings pdfSaveOptions.OutlineOptions.HeadingsOutlineLevels = 9; pdfSaveOptions.OutlineOptions.CreateMissingOutlineLevels = true; pdfSaveOptions.OutlineOptions.ExpandedOutlineLevels = 9; pdfSaveOptions.SaveFormat = SaveFormat.Pdf; doc.Save(MyDir + "CreateMissingOutlineLevels OUT.pdf", pdfSaveOptions); }
public static void Main() { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Initialize a new Workbook //Open an Excel file Workbook workbook = new Workbook(dataDir+ "input.xlsx"); //Implement one page per worksheet option PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.OnePagePerSheet = true; //Save the PDF file workbook.Save(dataDir+ "OutputFile.out.pdf", pdfSaveOptions); }
public static void Run() { // ExStart:SaveExcelIntoPdfWithOptimizedSize // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Load excel file into workbook object Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); // Save into Pdf with Minimum size PdfSaveOptions opts = new PdfSaveOptions(); opts.OptimizationType = Aspose.Cells.Rendering.PdfOptimizationType.MinimumSize; workbook.Save(dataDir + "OptimizedOutput_out.pdf", opts); // ExEnd:SaveExcelIntoPdfWithOptimizedSize }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); Project project = new Project(dataDir + "CreateProject2.mpp"); // ExStart:HideLegendsDuringSave SaveOptions saveOptions = new PdfSaveOptions(); // Set the LegendOnEachPage property to false to hide legends saveOptions.LegendOnEachPage = false; // ExEnd:HideLegendsDuringSave project.Save(dataDir + "HideLegendsDuringSave_out.pdf", saveOptions); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Initialize a new Workbook //Open an Excel file Workbook workbook = new Workbook(dataDir+ "input.xlsx"); //Instantiate the PdfSaveOptions PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); //Set Image Resample properties pdfSaveOptions.SetImageResample(300, 70); //Save the PDF file workbook.Save(dataDir+ "OutputFile.pdf", pdfSaveOptions); }
public static void Main() { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Initialize a new Workbook //Open an Excel file Workbook workbook = new Workbook(dataDir+ "input.xlsx"); //Instantiate the PdfSaveOptions PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); //Set Image Resample properties pdfSaveOptions.SetImageResample(300, 70); //Save the PDF file workbook.Save(dataDir+ "OutputFile.out.pdf", pdfSaveOptions); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // ExStart:FitContentsToCellSize Project project = new Project(dataDir + "CreateProject2.mpp"); SaveOptions saveOptions = new PdfSaveOptions(); // Set option fit content to true saveOptions.FitContent = true; saveOptions.Timescale = Timescale.Months; saveOptions.PresentationFormat = PresentationFormat.TaskUsage; project.Save(dataDir + "FitContentsToCellSize_out.pdf", saveOptions); // ExEnd:FitContentsToCellSize }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create and initialize an instance of Workbook Workbook book = new Workbook(dataDir + "TestBook.xlsx"); // Create and initialize an instance of PdfSaveOptions PdfSaveOptions saveOptions = new PdfSaveOptions(SaveFormat.Pdf); // Set AllColumnsInOnePagePerSheet to true saveOptions.AllColumnsInOnePagePerSheet = true; // Save Workbook to PDF fromart by passing the object of PdfSaveOptions dataDir = dataDir+ "output.out.pdf"; book.Save(dataDir, saveOptions); // ExEnd:1 Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir); }
public void SaveToPdfWithOutline() { //ExStart //ExFor:Document.Save(String, SaveOptions) //ExFor:PdfSaveOptions //ExFor:PdfSaveOptions.HeadingsOutlineLevels //ExFor:PdfSaveOptions.ExpandedOutlineLevels //ExSummary:Converts a whole document to PDF with three levels in the document outline. Document doc = new Document(MyDir + "Rendering.doc"); PdfSaveOptions options = new PdfSaveOptions(); options.OutlineOptions.HeadingsOutlineLevels = 3; options.OutlineOptions.ExpandedOutlineLevels = 1; doc.Save(MyDir + @"\Artifacts\Rendering.SaveToPdfWithOutline.pdf", options); //ExEnd }
public static void Run() { // ExStart:UsePDFSaveOptions // The path to the documents directory. string dataDir = RunExamples.GetDataDir_LoadSaveConvert(); // Call the diagram constructor to load diagram from a VSDX file Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); // Options when saving a diagram into the PDF format PdfSaveOptions options = new PdfSaveOptions(); // Discard saving background pages of the Visio diagram options.SaveForegroundPagesOnly = true; // Specify the quality of JPEG compression for images (if JPEG compression is used). Default is 95. options.JpegQuality = 100; // Specify default font name options.DefaultFont = "Arial"; // Conformance level for generated PDF document. options.Compliance = PdfCompliance.Pdf15; // Load the certificate from disk. // The other constructor overloads can be used to load certificates from different locations. X509Certificate2 cert = new X509Certificate2(dataDir + "certificate.pfx", "feyb4lgcfbme"); // Sets a digital signature details. If not set, then no signing will be performed. options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(cert, "Test Signing", "Aspose Office", DateTime.Now, PdfDigitalSignatureHashAlgorithm.Sha512); // Set encription details PdfEncryptionDetails encriptionDetails = new PdfEncryptionDetails("user password", "Owner Password", PdfEncryptionAlgorithm.RC4_128); options.EncryptionDetails = encriptionDetails; // Sets the number of pages to render in PDF. options.PageCount = 2; // Sets the 0-based index of the first page to render. Default is 0. options.PageIndex = 0; // Set page size PageSize pgSize = new PageSize(PaperSizeFormat.A1); options.PageSize = pgSize; // Save in any supported file format diagram.Save(dataDir + "UsePDFSaveOptions_out.pdf", options); // ExEnd:UsePDFSaveOptions }
public void CreateMissingOutlineLevels() { //ExStart //ExFor:Saving.PdfSaveOptions.OutlineOptions.CreateMissingOutlineLevels //ExSummary:Shows how to create missing outline levels saving the document in pdf Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Creating TOC entries builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1; builder.Writeln("Heading 1"); builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading4; builder.Writeln("Heading 1.1.1.1"); builder.Writeln("Heading 1.1.1.2"); builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading9; builder.Writeln("Heading 1.1.1.1.1.1.1.1.1"); builder.Writeln("Heading 1.1.1.1.1.1.1.1.2"); //Create "PdfSaveOptions" with some mandatory parameters //"HeadingsOutlineLevels" specifies how many levels of headings to include in the document outline //"CreateMissingOutlineLevels" determining whether or not to create missing heading levels PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.OutlineOptions.HeadingsOutlineLevels = 9; pdfSaveOptions.OutlineOptions.CreateMissingOutlineLevels = true; pdfSaveOptions.SaveFormat = SaveFormat.Pdf; doc.Save(MyDir + @"\Artifacts\CreateMissingOutlineLevels.pdf", pdfSaveOptions); //ExEnd //Bind pdf with Aspose PDF PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor(); bookmarkEditor.BindPdf(MyDir + @"\Artifacts\CreateMissingOutlineLevels.pdf"); //Get all bookmarks from the document Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks(); Assert.AreEqual(11, bookmarks.Count); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); //ExStart:CustomizeTextStyle Project project = new Project(dataDir + "CreateProject2.mpp"); SaveOptions options = new PdfSaveOptions(); options.PresentationFormat = PresentationFormat.ResourceSheet; TextStyle style = new TextStyle(); style.Color = Color.OrangeRed; style.FontStyle = FontStyle.Bold; style.FontStyle |= FontStyle.Italic; style.ItemType = TextItemType.OverallocatedResources; options.TextStyles = new List <TextStyle>(); options.TextStyles.Add(style); project.Save(dataDir + "CustomizeTextStyle_out.pdf", options); //ExEnd:CustomizeTextStyle }
///<Summary> /// ConvertProjectToPdf method to convert project to pdf format ///</Summary> public Response ConvertProjectToPdf(string fileName, string folderName, string outputType) { return(ProcessTask(fileName, folderName, ".pdf", false, false, delegate(string inFilePath, string outPath, string zipOutFolder) { Project project = new Project(inFilePath); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); if (outputType == "pdfa_1b") { pdfSaveOptions.Compliance = PdfCompliance.PdfA1b; } else if (outputType == "pdfa_1a") { pdfSaveOptions.Compliance = PdfCompliance.PdfA1a; } else if (outputType == "pdf_15") { pdfSaveOptions.Compliance = PdfCompliance.Pdf15; } project.Save(outPath, (SaveOptions)pdfSaveOptions); })); }
public static void Run() { // ExStart:SetConstraintStartNoEarlierThan // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // Create project instance Project project = new Project(dataDir + "ConstraintStartNoEarlierThan.mpp"); // Set constraint Start No Earlier Than on task with Id 1 Task summary = project.RootTask.Children.GetById(1); summary.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan); summary.Set(Tsk.ConstraintDate, new DateTime(2016, 12, 1, 9, 0, 0)); // Save project as pdf SaveOptions o = new PdfSaveOptions(); o.StartDate = project.Get(Prj.StartDate); o.Timescale = Timescale.ThirdsOfMonths; project.Save(dataDir + "project_StartNoEarlierThan_out.pdf", o); // ExEnd:SetConstraintStartNoEarlierThan }
static void PAdES_B_B() { // If using Professional version, put your serial key below. SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY"); var workbook = ExcelFile.Load("SimpleTemplate.xlsx"); // Create visual representation of digital signature at the beginning of the worksheet. var signature = workbook.Worksheets[0].Pictures.Add("GemBoxSignature.png", "B2"); var options = new PdfSaveOptions() { DigitalSignature = { CertificatePath = "GemBoxECDsa521.pfx", CertificatePassword = "******", Signature = signature, IsAdvancedElectronicSignature = true } }; workbook.Save("PDF Digital Signature.pdf", options); }
public static void Main() { string originalFile = @"..\Sample Data\BRAILLE CODES WITH TRANSLATION.pdf"; const string compressedFile = "CompressWithSaveOptions.pdf"; // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. using (PdfDocument pdf = new PdfDocument(originalFile)) { var saveOptions = new PdfSaveOptions { Compression = PdfCompression.Flate, UseObjectStreams = true, RemoveUnusedObjects = true, OptimizeIndirectObjects = true, WriteWithoutFormatting = true }; pdf.Save(compressedFile, saveOptions); } // NOTE: // This sample shows only one approach to reduce size of a PDF. // Please check CompressAllTechniques sample code to see more approaches. // https://github.com/BitMiracle/Docotic.Pdf.Samples/tree/master/Samples/Compression/CompressAllTechniques string message = string.Format( "Original file size: {0} bytes;\r\nCompressed file size: {1} bytes", new FileInfo(originalFile).Length, new FileInfo(compressedFile).Length ); Console.WriteLine(message); Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_LoadingAndSaving(); // Load the document into Aspose.Note. Document doc = new Document(dataDir + "Aspose.one"); // ExStart:KeepSOlidObjectsAlgoirthm-1 var pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.PageSplittingAlgorithm = new AlwaysSplitObjectsAlgorithm(); // Or pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm(); // Or pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(); // ExEnd:KeepSOlidObjectsAlgoirthm-1 // ExStart:KeepSOlidObjectsAlgoirthm-2 float heightLimitOfClonedPart = 500; pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm(heightLimitOfClonedPart); // Or pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(heightLimitOfClonedPart); // ExEnd:KeepSOlidObjectsAlgoirthm-2 // ExStart:KeepSOlidObjectsAlgoirthm-3 pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(100); // ExEnd:KeepSOlidObjectsAlgoirthm-3 // Or // ExStart:KeepSOlidObjectsAlgoirthm-4 pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(400); // ExEnd:KeepSOlidObjectsAlgoirthm-4 dataDir = dataDir + "UsingKeepSOlidObjectsAlgoirthm_out.pdf"; doc.Save(dataDir); Console.WriteLine("\nPage splitt successfully using keep solid objects algoirthm method."); }
static void Main(string[] args) { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); DocumentModel document = DocumentModel.Load("DigitalSignature.docx"); string pathToResources = "Resources"; // Signature line added with MS Word -> Insert tab -> Signature Line button by default has description 'Microsoft Office Signature Line...'. var signatureLine = document.GetChildElements(true).OfType <DrawingElement>().FirstOrDefault( de => de.Metadata.Description == "Microsoft Office Signature Line..."); var signature = new Picture(document, Path.Combine(pathToResources, "GemBoxSignature.png")); // Signature in this document will be 1.5 cm right of TopLeft position of signature line // and 0.5 cm below of TopLeft position of signature line. signature.Layout = Layout.Floating( new HorizontalPosition(1.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page), new VerticalPosition(0.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page), signature.Layout.Size); var options = new PdfSaveOptions() { DigitalSignature = { CertificatePath = Path.Combine(pathToResources, "GemBoxSampleExplorer.pfx"), CertificatePassword = "******", // Placeholder where signature should be visualized. SignatureLine = signatureLine, // Visual representation of digital signature. Signature = signature } }; document.Save("PDF Digital Signature.pdf", options); }
public void PdfImageComppression() { //ExStart:PdfImageComppression Document doc = new Document(MyDir + "Rendering.docx"); PdfSaveOptions saveOptions = new PdfSaveOptions { ImageCompression = PdfImageCompression.Jpeg, PreserveFormFields = true }; doc.Save(ArtifactsDir + "WorkingWithPdfSaveOptions.PdfImageCompression.pdf", saveOptions); PdfSaveOptions saveOptionsA1B = new PdfSaveOptions { Compliance = PdfCompliance.PdfA1b, ImageCompression = PdfImageCompression.Jpeg, JpegQuality = 100, // Use JPEG compression at 50% quality to reduce file size. ImageColorSpaceExportMode = PdfImageColorSpaceExportMode.SimpleCmyk }; doc.Save(ArtifactsDir + "WorkingWithPdfSaveOptions.PdfImageCompression.Pdf_A1b.pdf", saveOptionsA1B); //ExEnd:PdfImageComppression }
public static void Run() { //ExStart: ReducingGapBetweenTasksListAndFooter // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); //Read the MPP file. Project project = new Project(dataDir + "CreateProject2.mpp"); //Use ReduceFooterGap property to reduce the gap between list of tasks and Footer var imageSaveOptions = new ImageSaveOptions(SaveFileFormat.PNG) { ReduceFooterGap = true, /* set to true */ SaveToSeparateFiles = true, PageSize = PageSize.A0, Timescale = Timescale.Days }; project.Save(dataDir + "ReducingGapBetweenTasksListAndFooter_out.png", (SaveOptions)imageSaveOptions); var pdfSaveOptions = new PdfSaveOptions { ReduceFooterGap = true, /* set to true */ SaveToSeparateFiles = true, PageSize = PageSize.A0, Timescale = Timescale.Days }; project.Save(dataDir + "ReducingGapBetweenTasksListAndFooter_out.pdf", (SaveOptions)pdfSaveOptions); var htmlSaveOptions = new HtmlSaveOptions { ReduceFooterGap = false, // set to true IncludeProjectNameInPageHeader = false, IncludeProjectNameInTitle = false, PageSize = PageSize.A0, Timescale = Timescale.Days }; project.Save(dataDir + "ReducingGapBetweenTasksListAndFooter_out.html", htmlSaveOptions); //ExEnd: ReducingGapBetweenTasksListAndFooter }
static void Main() { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); var document = DocumentModel.Load("DigitalSignature.docx"); // Get placeholder where signature should be visualized. // Signature line was added with: Microsoft Word => Insert => Signature Line // By default it'll have "Microsoft Office Signature Line..." description. var signatureLine = document.GetChildElements(true).OfType <DrawingElement>().FirstOrDefault( de => de.Metadata.Description == "Microsoft Office Signature Line..."); // Create visual representation of digital signature. var signature = new Picture(document, "GemBoxSignature.png"); // Position signature image in a signature line. // Image will be placed 1.5cm right and 0.5cm below the top-left corner of signature line. signature.Layout = Layout.Floating( new HorizontalPosition(1.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page), new VerticalPosition(0.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page), signature.Layout.Size); var options = new PdfSaveOptions() { DigitalSignature = { CertificatePath = "GemBoxExampleExplorer.pfx", CertificatePassword = "******", SignatureLine = signatureLine, Signature = signature } }; document.Save("PDF Digital Signature.pdf", options); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "ProtectDocumentWithCertificate.pdf"; using (PdfDocument pdf = new PdfDocument()) { pdf.Pages[0].Canvas.DrawString("Hello World!"); PdfPublicKeyEncryptionHandler handler = createEncryptionHandler(); handler.Algorithm = PdfEncryptionAlgorithm.Aes256Bit; var saveOptions = new PdfSaveOptions { EncryptionHandler = handler }; pdf.Save(pathToFile, saveOptions); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public void CreateBookmark() { //ExStart:CreateBookmark Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.StartBookmark("My Bookmark"); builder.Writeln("Text inside a bookmark."); builder.StartBookmark("Nested Bookmark"); builder.Writeln("Text inside a NestedBookmark."); builder.EndBookmark("Nested Bookmark"); builder.Writeln("Text after Nested Bookmark."); builder.EndBookmark("My Bookmark"); PdfSaveOptions options = new PdfSaveOptions(); options.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1); options.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2); doc.Save(ArtifactsDir + "WorkingWithBookmarks.CreateBookmark.pdf", options); //ExEnd:CreateBookmark }
///<Summary> /// ConvertXlsToPDF method to convert XLS file to PDF ///</Summary> public Response ConvertXlsToPDF(string fileName, string folderName, string userEmail, string outputType) { return(ProcessTask(fileName, folderName, ".pdf", false, false, delegate(string inFilePath, string outPath, string zipOutFolder) { Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(inFilePath); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); if (outputType == "pdfa_1b") { pdfSaveOptions.Compliance = Cells.Rendering.PdfCompliance.PdfA1b; } else if (outputType == "pdfa_1a") { pdfSaveOptions.Compliance = Cells.Rendering.PdfCompliance.PdfA1a; } else if (outputType == "pdf_15" || outputType == "pdf") { pdfSaveOptions.Compliance = Cells.Rendering.PdfCompliance.None; } workbook.Save(outPath, pdfSaveOptions); })); }
}//End CustomPivotTableGlobalizationSettings public static void Run() { // ExStart:CustomizePivotTableGlobalSettings // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Load your excel file Workbook wb = new Workbook(dataDir + "samplePivotTableGlobalizationSettings.xlsx"); //Setting Custom Pivot Table Globalization Settings wb.Settings.GlobalizationSettings = new CustomPivotTableGlobalizationSettings(); //Hide first worksheet that contains the data of the pivot table wb.Worksheets[0].IsVisible = false; //Access second worksheet Worksheet ws = wb.Worksheets[1]; //Access the pivot table, refresh and calculate its data PivotTable pt = ws.PivotTables[0]; pt.RefreshDataFlag = true; pt.RefreshData(); pt.CalculateData(); pt.RefreshDataFlag = false; //Pdf save options - save entire worksheet on a single pdf page PdfSaveOptions options = new PdfSaveOptions(); options.OnePagePerSheet = true; //Save the output pdf wb.Save(dataDir + "outputPivotTableGlobalizationSettings.pdf", options); // ExEnd:CustomizePivotTableGlobalSettings }
public void ImageCompression() { //ExStart:PdfImageCompression Document doc = new Document(MyDir + "Rendering.docx"); PdfSaveOptions saveOptions = new PdfSaveOptions { ImageCompression = PdfImageCompression.Jpeg, PreserveFormFields = true }; doc.Save(ArtifactsDir + "WorkingWithPdfSaveOptions.PdfImageCompression.pdf", saveOptions); PdfSaveOptions saveOptionsA2U = new PdfSaveOptions { Compliance = PdfCompliance.PdfA2u, ImageCompression = PdfImageCompression.Jpeg, JpegQuality = 100, // Use JPEG compression at 50% quality to reduce file size. }; doc.Save(ArtifactsDir + "WorkingWithPdfSaveOptions.PdfImageCompression_A2u.pdf", saveOptionsA2U); //ExEnd:PdfImageComppression }
public void WithoutUpdateFields() { //ExStart //ExFor:SaveOptions.UpdateFields //ExSummary:Shows how to update fields before saving into a PDF document. Document doc = DocumentHelper.CreateDocumentFillWithDummyText(); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.UpdateFields = false; doc.Save(MyDir + @"\Artifacts\UpdateFields_False.pdf", pdfSaveOptions); //ExEnd Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(MyDir + @"\Artifacts\UpdateFields_False.pdf"); // Get text fragment by search String TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Page of"); pdfDocument.Pages.Accept(textFragmentAbsorber); // Assert that fields are not updated Assert.AreEqual("Page of", textFragmentAbsorber.TextFragments[1].Text); }
public static void Run() { //Output directory string outputDir = RunExamples.Get_OutputDirectory(); //Create workbook object Workbook wb = new Workbook(); //Access first worksheet Worksheet ws = wb.Worksheets[0]; //Access cell B5 and add some message inside it Cell cell = ws.Cells["B5"]; cell.PutValue("This PDF format is compatible with PDFA-1a."); //Create pdf save options and set its compliance to PDFA-1a PdfSaveOptions opts = new PdfSaveOptions(); opts.Compliance = PdfCompliance.PdfA1a; //Save the output pdf wb.Save(outputDir + "outputCompliancePdfA1a.pdf", opts); }
public void ImageCompression() { //ExStart //ExFor:PdfSaveOptions.Compliance //ExFor:PdfSaveOptions.ImageCompression //ExFor:PdfSaveOptions.JpegQuality //ExFor:PdfImageCompression //ExFor:PdfCompliance //ExSummary:Demonstrates how to save images to PDF using JPEG encoding to decrease file size. Document doc = new Document(MyDir + "SaveOptions.PdfImageCompression.rtf"); PdfSaveOptions options = new PdfSaveOptions(); options.ImageCompression = PdfImageCompression.Jpeg; options.PreserveFormFields = true; doc.Save(MyDir + @"\Artifacts\SaveOptions.PdfImageCompression Out.pdf", options); PdfSaveOptions optionsA1b = new PdfSaveOptions(); optionsA1b.Compliance = PdfCompliance.PdfA1b; optionsA1b.ImageCompression = PdfImageCompression.Jpeg; optionsA1b.JpegQuality = 100; // Use JPEG compression at 50% quality to reduce file size. doc.Save(MyDir + @"\Artifacts\SaveOptions.PdfImageComppression PDF_A_1_B Out.pdf", optionsA1b); //ExEnd PdfSaveOptions optionsA1a = new PdfSaveOptions(); optionsA1a.Compliance = PdfCompliance.PdfA1a; optionsA1a.ExportDocumentStructure = true; optionsA1a.ImageCompression = PdfImageCompression.Jpeg; doc.Save(MyDir + @"\Artifacts\SaveOptions.PdfImageComppression PDF_A_1_A Out.pdf", optionsA1a); //ExEnd }
public static void Run() { // ExStart:SpecifySaveOptions // ExFor:Document // ExFor:Document.Save(System.String, Aspose.Note.Saving.SaveOptions) // ExFor:PdfSaveOptions // ExFor:SaveOptions.PageIndex // ExFor:SaveOptions.PageCount // ExFor:PdfSaveOptions.ImageCompression // ExFor:PdfSaveOptions.JpegQuality // ExSummary:Shows how to save a document in pdf format using specific settings. // The path to the documents directory. string dataDir = RunExamples.GetDataDir_LoadingAndSaving(); // Load the document into Aspose.Note. Document doc = new Document(dataDir + "Aspose.one"); // Initialize PdfSaveOptions object PdfSaveOptions opts = new PdfSaveOptions { // Use Jpeg compression ImageCompression = Saving.Pdf.PdfImageCompression.Jpeg, // Quality for JPEG compression JpegQuality = 90 }; dataDir = dataDir + "Document.SaveWithOptions_out.pdf"; doc.Save(dataDir, opts); // ExEnd:SpecifySaveOptions Console.WriteLine("\nOneNote document saved successfully.\nFile saved at " + dataDir); }
public void CreateMissingOutlineLevels() { //ExStart //ExFor:Saving.PdfSaveOptions.OutlineOptions.CreateMissingOutlineLevels //ExSummary:Shows how to create missing outline levels saving the document in pdf Aspose.Words.Document doc = new Aspose.Words.Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Creating TOC entries builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1; builder.Writeln("Heading 1"); builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading4; builder.Writeln("Heading 1.1.1.1"); builder.Writeln("Heading 1.1.1.2"); builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading9; builder.Writeln("Heading 1.1.1.1.1.1.1.1.1"); builder.Writeln("Heading 1.1.1.1.1.1.1.1.2"); //Create "PdfSaveOptions" with some mandatory parameters //"HeadingsOutlineLevels" specifies how many levels of headings to include in the document outline //"CreateMissingOutlineLevels" determining whether or not to create missing heading levels PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.OutlineOptions.HeadingsOutlineLevels = 9; pdfSaveOptions.OutlineOptions.CreateMissingOutlineLevels = true; pdfSaveOptions.SaveFormat = SaveFormat.Pdf; doc.Save(MyDir + "CreateMissingOutlineLevels.pdf", pdfSaveOptions); //ExEnd }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); // ExStart:1 // Load your source workbook containing MINIFS and MAXIFS functions Workbook workbook = new Workbook(sourceDir + "sampleMINIFSAndMAXIFS.xlsx"); // Perform Aspose.Cells formula calculation workbook.CalculateFormula(); // Save the calculations result in pdf format PdfSaveOptions options = new PdfSaveOptions(); options.OnePagePerSheet = true; workbook.Save(outputDir + "outputMINIFSAndMAXIFS.pdf", options); // ExEnd:1 Console.WriteLine("MINIFSAndMAXIFS executed successfully."); }
public void WorkWithTextCompression() { // ExStart // ExFor: PdfSaveOptions.TextCompression // ExFor: PdfTextCompression // ExSummary: Shows how to set a compression type to be used for all content streams except images. var project = new Project(DataDir + "EstimatedMilestoneTasks.mpp"); var options = new PdfSaveOptions(); // set compression type to be used for all content streams except images options.TextCompression = PdfTextCompression.Flate; // tune additional properties // set the <see cref="P:Aspose.Tasks.Saving.SaveOptions.PresentationFormat" /> in which the document will be saved. options.PresentationFormat = PresentationFormat.GanttChart; // set a desired conformance level for generated PDF document options.Compliance = PdfCompliance.PdfA1b; project.Save(OutDir + "WorkWithTextCompression_out.pdf", options); // ExEnd }
public void SaveToMultiplePdfFiles() { // ExStart // ExFor: PdfSaveOptions // ExFor: PdfSaveOptions.#ctor // ExFor: PdfSaveOptions.SaveToSeparateFiles // ExFor: PdfSaveOptions.Pages // ExFor: SaveOptions.PageCount // ExSummary: Shows how to save selected pages of a project into PDF file. var project = new Project(DataDir + "Software Development Plan.mpp"); var options = new PdfSaveOptions(); options.SaveToSeparateFiles = true; options.Pages = new List <int>(); // lets check the number of pages can be exported Console.WriteLine("Page Count: " + options.PageCount); options.Pages.Add(1); options.Pages.Add(4); project.Save(OutDir + "SaveToMultiplePDFFiles_out.pdf", options); // ExEnd }
/// <summary> /// GetSaveOptions /// </summary> /// <param name="outputType"></param> /// <returns></returns> protected SaveInfo GetSaveOptions(string outputType) { var saveFormatInfo = new SaveInfo { SaveOptions = null }; switch (outputType) { case "pdf": { saveFormatInfo.SaveFileFormat = SaveFileFormat.PDF; saveFormatInfo.SaveOptions = new PdfSaveOptions(); break; } case "pdfa_1a": { saveFormatInfo.SaveFileFormat = SaveFileFormat.PDF; PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.Compliance = PdfCompliance.PdfA1a; saveFormatInfo.SaveOptions = pdfSaveOptions; break; } case "pdfa_1b": { saveFormatInfo.SaveFileFormat = SaveFileFormat.PDF; PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.Compliance = PdfCompliance.PdfA1b; saveFormatInfo.SaveOptions = pdfSaveOptions; break; } case "pdf_15": { saveFormatInfo.SaveFileFormat = SaveFileFormat.PDF; PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); pdfSaveOptions.Compliance = PdfCompliance.Pdf15; saveFormatInfo.SaveOptions = pdfSaveOptions; break; } case "html": { saveFormatInfo.SaveFileFormat = SaveFileFormat.HTML; saveFormatInfo.SaveOptions = new HTMLSaveOptions(); break; } case "jpg": { saveFormatInfo.SaveFileFormat = SaveFileFormat.JPEG; break; } case "png": { saveFormatInfo.SaveFileFormat = SaveFileFormat.PNG; break; } case "bmp": { saveFormatInfo.SaveFileFormat = SaveFileFormat.BMP; break; } case "svg": { saveFormatInfo.SaveFileFormat = SaveFileFormat.SVG; break; } case "tiff": { saveFormatInfo.SaveFileFormat = SaveFileFormat.TIFF; break; } case "xps": { saveFormatInfo.SaveFileFormat = SaveFileFormat.XPS; break; } case "gif": { saveFormatInfo.SaveFileFormat = SaveFileFormat.GIF; break; } case "emf": { saveFormatInfo.SaveFileFormat = SaveFileFormat.EMF; break; } case "vsdx": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VSDX; break; } case "vsx": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VSX; break; } case "vtx": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VTX; break; } case "vdx": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VDX; break; } case "vssx": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VSSX; break; } case "vstx": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VSTX; break; } case "vsdm": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VSDM; break; } case "vssm": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VSSM; break; } case "vstm": { saveFormatInfo.SaveFileFormat = SaveFileFormat.VSTM; break; } default: throw new Exception("Invalid file format"); } return(saveFormatInfo); }
public void BookmarkLevels() { //ExStart //ExFor:BookmarksOutlineLevelCollection //ExFor:BookmarksOutlineLevelCollection.Add(String, Int32) //ExFor:BookmarksOutlineLevelCollection.Clear //ExFor:BookmarksOutlineLevelCollection.Contains(System.String) //ExFor:BookmarksOutlineLevelCollection.Count //ExFor:BookmarksOutlineLevelCollection.IndexOfKey(System.String) //ExFor:BookmarksOutlineLevelCollection.Item(System.Int32) //ExFor:BookmarksOutlineLevelCollection.Item(System.String) //ExFor:BookmarksOutlineLevelCollection.Remove(System.String) //ExFor:BookmarksOutlineLevelCollection.RemoveAt(System.Int32) //ExFor:OutlineOptions.BookmarksOutlineLevels //ExSummary:Shows how to set outline levels for bookmarks. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a bookmark with another bookmark nested inside it. builder.StartBookmark("Bookmark 1"); builder.Writeln("Text inside Bookmark 1."); builder.StartBookmark("Bookmark 2"); builder.Writeln("Text inside Bookmark 1 and 2."); builder.EndBookmark("Bookmark 2"); builder.Writeln("Text inside Bookmark 1."); builder.EndBookmark("Bookmark 1"); // Insert another bookmark. builder.StartBookmark("Bookmark 3"); builder.Writeln("Text inside Bookmark 3."); builder.EndBookmark("Bookmark 3"); // When saving to .pdf, bookmarks can be accessed via a drop-down menu and used as anchors by most readers. // Bookmarks can also have numeric values for outline levels, // enabling lower level outline entries to hide higher-level child entries when collapsed in the reader. PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.OutlineOptions.BookmarksOutlineLevels; outlineLevels.Add("Bookmark 1", 1); outlineLevels.Add("Bookmark 2", 2); outlineLevels.Add("Bookmark 3", 3); Assert.AreEqual(3, outlineLevels.Count); Assert.True(outlineLevels.Contains("Bookmark 1")); Assert.AreEqual(1, outlineLevels[0]); Assert.AreEqual(2, outlineLevels["Bookmark 2"]); Assert.AreEqual(2, outlineLevels.IndexOfKey("Bookmark 3")); // We can remove two elements so that only the outline level designation for "Bookmark 1" is left. outlineLevels.RemoveAt(2); outlineLevels.Remove("Bookmark 2"); // There are nine outline levels. Their numbering will be optimized during the save operation. // In this case, levels "5" and "9" will become "2" and "3". outlineLevels.Add("Bookmark 2", 5); outlineLevels.Add("Bookmark 3", 9); doc.Save(ArtifactsDir + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions); // Emptying this collection will preserve the bookmarks and put them all on the same outline level. outlineLevels.Clear(); //ExEnd #if NET462 || NETCOREAPP2_1 || JAVA PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor(); bookmarkEditor.BindPdf(ArtifactsDir + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf"); Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks(); Assert.AreEqual(3, bookmarks.Count); Assert.AreEqual("Bookmark 1", bookmarks[0].Title); Assert.AreEqual("Bookmark 2", bookmarks[1].Title); Assert.AreEqual("Bookmark 3", bookmarks[2].Title); #endif }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); //Load source Excel file Workbook wb = new Workbook(sourceDir + "samplePdfBookmarkEntry_DestinationName.xlsx"); //Access first worksheet Worksheet ws = wb.Worksheets[0]; //Access cell C5 Cell cell = ws.Cells["C5"]; //Create Bookmark and Destination for this cell PdfBookmarkEntry bookmarkEntry = new PdfBookmarkEntry(); bookmarkEntry.Text = "Text"; bookmarkEntry.Destination = cell; bookmarkEntry.DestinationName = "AsposeCells--" + cell.Name; //Access cell G56 cell = ws.Cells["G56"]; //Create Sub-Bookmark and Destination for this cell PdfBookmarkEntry subbookmarkEntry1 = new PdfBookmarkEntry(); subbookmarkEntry1.Text = "Text1"; subbookmarkEntry1.Destination = cell; subbookmarkEntry1.DestinationName = "AsposeCells--" + cell.Name; //Access cell L4 cell = ws.Cells["L4"]; //Create Sub-Bookmark and Destination for this cell PdfBookmarkEntry subbookmarkEntry2 = new PdfBookmarkEntry(); subbookmarkEntry2.Text = "Text2"; subbookmarkEntry2.Destination = cell; subbookmarkEntry2.DestinationName = "AsposeCells--" + cell.Name; //Add Sub-Bookmarks in list ArrayList list = new ArrayList(); list.Add(subbookmarkEntry1); list.Add(subbookmarkEntry2); //Assign Sub-Bookmarks list to Bookmark Sub-Entry bookmarkEntry.SubEntry = list; //Create PdfSaveOptions and assign Bookmark to it PdfSaveOptions opts = new PdfSaveOptions(); opts.Bookmark = bookmarkEntry; //Save the workbook in Pdf format with given pdf save options wb.Save(outputDir + "outputPdfBookmarkEntry_DestinationName.pdf", opts); Console.WriteLine("AddPDFBookmarksWithNamedDestinations executed successfully.\r\n"); }
//public static bool VerifyDoc(string signedDoc, string distinguishedName) //{ // PdfDocument doc = new PdfDocument(signedDoc); // PdfPageBase page = doc.Pages[0]; // PdfSignature pdfSignature = new PdfSignature(page,) //} #endregion #region 3rd party library SautinSoft public static string SignDocument(string loadPath) { string signedDoc = @"SignedDoc.pdf"; //string signedDoc = "Pitambar_resume_Signed.pdf"; DocumentCore documentCore = DocumentCore.Load(loadPath); Shape signatureShape = new Shape(documentCore, Layout.Floating( new HorizontalPosition(0f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin), new VerticalPosition(0f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), new Size(1, 1))); ((FloatingLayout)signatureShape.Layout).WrappingStyle = WrappingStyle.InFrontOfText; signatureShape.Outline.Fill.SetEmpty(); // Find a first paragraph and insert our Shape inside it. Paragraph firstPar = documentCore.GetChildElements(true).OfType <Paragraph>().FirstOrDefault(); firstPar.Inlines.Add(signatureShape); // Picture which symbolizes a handwritten signature. Picture signaturePict = new Picture(documentCore, @"..\..\..\nishicon.ico"); // Signature picture will be positioned: // 14.5 cm from Top of the Shape. // 4.5 cm from Left of the Shape. signaturePict.Layout = Layout.Floating( new HorizontalPosition(4.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page), new VerticalPosition(14.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page), new Size(20, 10, LengthUnit.Millimeter)); PdfSaveOptions options = new PdfSaveOptions(); // Path to the certificate (*.pfx). options.DigitalSignature.CertificatePath = @"..\..\..\NewSignKey.pfx"; // The password for the certificate. // Each certificate is protected by a password. // The reason is to prevent unauthorized the using of the certificate. options.DigitalSignature.CertificatePassword = "******"; // Additional information about the certificate. options.DigitalSignature.Location = "Kathmandu"; options.DigitalSignature.Reason = "for demo"; options.DigitalSignature.ContactInfo = "*****@*****.**"; // Placeholder where signature should be visualized. options.DigitalSignature.SignatureLine = signatureShape; // Visual representation of digital signature. options.DigitalSignature.Signature = signaturePict; documentCore.Save(signedDoc, options); // Open the result for demonstation purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(signedDoc) { UseShellExecute = true }); return(""); }
/// <summary> /// Load an existing document (*.docx, *.rtf, *.pdf, *.html, *.txt, *.pdf) and save it in a PDF document with the digital signature. /// </summary> /// <remarks> /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/digital-signature-net-csharp-vb.php /// </remarks> public static void DigitalSignature() { // Path to a loadable document. string loadPath = @"..\..\digitalsignature.docx"; string savePath = "Result.pdf"; DocumentCore dc = DocumentCore.Load(loadPath); // Create a new invisible Shape for the digital signature. // Place the Shape into top-left corner (0 mm, 0 mm) of page. Shape signatureShape = new Shape(dc, Layout.Floating(new HorizontalPosition(0f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin), new VerticalPosition(0f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), new Size(1, 1))); ((FloatingLayout)signatureShape.Layout).WrappingStyle = WrappingStyle.InFrontOfText; signatureShape.Outline.Fill.SetEmpty(); // Find a first paragraph and insert our Shape inside it. Paragraph firstPar = dc.GetChildElements(true).OfType <Paragraph>().FirstOrDefault(); firstPar.Inlines.Add(signatureShape); // Picture which symbolizes a handwritten signature. Picture signaturePict = new Picture(dc, @"..\..\signature.png"); // Signature picture will be positioned: // 14.5 cm from Top of the Shape. // 4.5 cm from Left of the Shape. signaturePict.Layout = Layout.Floating( new HorizontalPosition(4.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page), new VerticalPosition(14.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page), new Size(20, 10, LengthUnit.Millimeter)); PdfSaveOptions options = new PdfSaveOptions(); // Path to the certificate (*.pfx). options.DigitalSignature.CertificatePath = @"..\..\sautinsoft.pfx"; // The password for the certificate. // Each certificate is protected by a password. // The reason is to prevent unauthorized the using of the certificate. options.DigitalSignature.CertificatePassword = "******"; // Additional information about the certificate. options.DigitalSignature.Location = "World Wide Web"; options.DigitalSignature.Reason = "Document.Net by SautinSoft"; options.DigitalSignature.ContactInfo = "*****@*****.**"; // Placeholder where signature should be visualized. options.DigitalSignature.SignatureLine = signatureShape; // Visual representation of digital signature. options.DigitalSignature.Signature = signaturePict; dc.Save(savePath, options); // Open the result for demonstration purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(savePath) { UseShellExecute = true }); }
public static byte[] PerformOCRTesseract(byte[] image) { // Specify that Tesseract use three 3 languages: English, Russian and Vietnamese. string tesseractLanguages = "rus+eng+vie"; // A path to a folder which contains languages data files and font file "pdf.ttf". // Language data files can be found here: // Good and fast: https://github.com/tesseract-ocr/tessdata_fast // or // Best and slow: https://github.com/tesseract-ocr/tessdata_best // Also this folder must have write permissions. string tesseractData = Path.GetFullPath(@"..\..\tessdata\"); // A path for a temporary PDF file (because Tesseract returns OCR result as PDF document) string tempFile = Path.Combine(tesseractData, Path.GetRandomFileName()); try { using (Tesseract.IResultRenderer renderer = Tesseract.PdfResultRenderer.CreatePdfRenderer(tempFile, tesseractData, true)) { using (renderer.BeginDocument("Serachablepdf")) { using (Tesseract.TesseractEngine engine = new Tesseract.TesseractEngine(tesseractData, tesseractLanguages, Tesseract.EngineMode.Default)) { engine.DefaultPageSegMode = Tesseract.PageSegMode.Auto; using (MemoryStream msImg = new MemoryStream(image)) { System.Drawing.Image imgWithText = System.Drawing.Image.FromStream(msImg); for (int i = 0; i < imgWithText.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); i++) { imgWithText.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, i); using (MemoryStream ms = new MemoryStream()) { imgWithText.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] imgBytes = ms.ToArray(); using (Tesseract.Pix img = Tesseract.Pix.LoadFromMemory(imgBytes)) { using (var page = engine.Process(img, "Serachablepdf")) { renderer.AddPage(page); } } } } } } } } PdfLoadOptions pl = new PdfLoadOptions(); pl.ShowInvisibleText = true; pl.PreserveEmbeddedFonts = false; pl.ConversionMode = PdfConversionMode.Continuous; DocumentCore dc = DocumentCore.Load(File.OpenRead(tempFile + @".pdf"), pl); byte[] returnPdf; using (MemoryStream ms = new MemoryStream()) { PdfSaveOptions ps = new PdfSaveOptions(); dc.Save(ms, ps); returnPdf = ms.ToArray(); } return(returnPdf); } catch (Exception e) { Console.WriteLine(); Console.WriteLine("Please be sure that you have Language data files (*.traineddata) in your folder \"tessdata\""); Console.WriteLine("The Language data files can be download from here: https://github.com/tesseract-ocr/tessdata_fast"); Console.ReadKey(); throw new Exception("Error Tesseract: " + e.Message); } finally { if (File.Exists(tempFile + ".pdf")) { File.Delete(tempFile + ".pdf"); } } }