public void WithUpdateFields() { Document doc = DocumentHelper.CreateDocumentFillWithDummyText(); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions { UpdateFields = true }; doc.Save(MyDir + @"\Artifacts\UpdateFields_False.pdf", pdfSaveOptions); Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(MyDir + @"\Artifacts\UpdateFields_False.pdf"); // Get text fragment by search String from PDF document TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Page 1 of 2"); pdfDocument.Pages.Accept(textFragmentAbsorber); // Assert that fields are updated Assert.AreEqual("Page 1 of 2", textFragmentAbsorber.TextFragments[1].Text); }
public void ImageCompression() { //ExStart //ExFor:PdfSaveOptions.Compliance //ExFor:PdfSaveOptions.ImageCompression //ExFor:PdfSaveOptions.ImageColorSpaceExportMode //ExFor:PdfSaveOptions.JpegQuality //ExFor:PdfImageCompression //ExFor:PdfCompliance //ExFor:PdfImageColorSpaceExportMode //ExSummary:Shows 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 { ImageCompression = PdfImageCompression.Jpeg, PreserveFormFields = true }; doc.Save(ArtifactsDir + "SaveOptions.PdfImageCompression.pdf", options); PdfSaveOptions optionsA1B = 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 + "SaveOptions.PdfImageComppression PDF_A_1_B.pdf", optionsA1B); //ExEnd PdfSaveOptions optionsA1A = new PdfSaveOptions { Compliance = PdfCompliance.PdfA1a, ExportDocumentStructure = true, ImageCompression = PdfImageCompression.Jpeg }; doc.Save(ArtifactsDir + "SaveOptions.PdfImageComppression PDF_A_1_A.pdf", optionsA1A); }
public void WindowsBarPdfTitle() { //ExStart //ExFor:PdfSaveOptions.DisplayDocTitle //ExSummary:Shows how to display title of the document as title bar. Document doc = new Document(MyDir + "Rendering.doc"); doc.BuiltInDocumentProperties.Title = "Windows bar pdf title"; PdfSaveOptions pdfSaveOptions = new PdfSaveOptions { DisplayDocTitle = true }; doc.Save(MyDir + @"\Artifacts\PdfTitle.pdf", pdfSaveOptions); //ExEnd Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(MyDir + @"\Artifacts\PdfTitle.pdf"); Assert.IsTrue(pdfDocument.DisplayDocTitle); Assert.AreEqual("Windows bar pdf title", pdfDocument.Info.Title); }
public void PreblendImages() { //ExStart //ExFor:PdfSaveOptions.PreblendImages //ExSummary:Shows how to preblend images with transparent backgrounds. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Image img = Image.FromFile(ImageDir + "TransparentBG.png"); builder.InsertImage(img); // Create a PdfSaveOptions object and setting this flag may change the quality and size of the output .pdf // because of the way some images are rendered PdfSaveOptions options = new PdfSaveOptions(); options.PreblendImages = true; doc.Save(ArtifactsDir + "PdfSaveOptions.PreblendImages.pdf", options); //ExEnd }
public void CustomPropertiesExport() { //ExStart //ExFor:PdfCustomPropertiesExport //ExFor:PdfSaveOptions.CustomPropertiesExport //ExFor:SaveOptions.DmlEffectsRenderingMode //ExSummary:Shows how to export custom properties while saving to .pdf. Document doc = new Document(); // Add a custom document property that doesn't use the name of some built in properties doc.CustomDocumentProperties.Add("Company", "My value"); // Configure the PdfSaveOptions like this will display the properties // in the "Document Properties" menu of Adobe Acrobat Pro PdfSaveOptions options = new PdfSaveOptions(); options.CustomPropertiesExport = PdfCustomPropertiesExport.Standard; doc.Save(ArtifactsDir + "PdfSaveOptions.CustomPropertiesExport.pdf", options); //ExEnd }
public void HeaderFooterBookmarksExportMode(HeaderFooterBookmarksExportMode headerFooterBookmarksExportMode) { //ExStart //ExFor:HeaderFooterBookmarksExportMode //ExSummary:Shows how bookmarks in headers/footers are exported to pdf Document doc = new Document(MyDir + "PdfSaveOption.HeaderFooterBookmarksExportMode.docx"); // You can specify how bookmarks in headers/footers are exported. // There is a several options for this: // "None" - Bookmarks in headers/footers are not exported. // "First" - Only bookmark in first header/footer of the section is exported. // "All" - Bookmarks in all headers/footers are exported. PdfSaveOptions saveOptions = new PdfSaveOptions { HeaderFooterBookmarksExportMode = headerFooterBookmarksExportMode, OutlineOptions = { DefaultBookmarksOutlineLevel = 1 } }; doc.Save(MyDir + @"\Artifacts\PdfSaveOption.HeaderFooterBookmarksExportMode.pdf", saveOptions); //ExEnd }
public void PreblendImagesNetStandard2() { //ExStart //ExFor:PdfSaveOptions.PreblendImages //ExSummary:Shows how to preblend images with transparent backgrounds (.NetStandard 2.0). Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); using (SKBitmap image = SKBitmap.Decode(ImageDir + "TransparentBG.png")) { builder.InsertImage(image); } // Create a PdfSaveOptions object and setting this flag may change the quality and size of the output .pdf // because of the way some images are rendered PdfSaveOptions options = new PdfSaveOptions(); options.PreblendImages = true; doc.Save(ArtifactsDir + "PdfSaveOptions.PreblendImages.pdf", options); //ExEnd }
public void PdfDigitalSignature() { //ExStart //ExFor:PdfDigitalSignatureDetails //ExFor:PdfDigitalSignatureDetails.#ctor //ExFor:PdfDigitalSignatureDetails.#ctor(CertificateHolder, String, String, DateTime) //ExFor:PdfDigitalSignatureDetails.HashAlgorithm //ExFor:PdfDigitalSignatureDetails.Location //ExFor:PdfDigitalSignatureDetails.Reason //ExFor:PdfDigitalSignatureDetails.SignatureDate //ExFor:PdfDigitalSignatureHashAlgorithm //ExFor:PdfSaveOptions.DigitalSignatureDetails //ExSummary:Shows how to sign a generated PDF using Aspose.Words. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Signed PDF contents."); // Load the certificate from disk // The other constructor overloads can be used to load certificates from different locations CertificateHolder certificateHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw"); // Pass the certificate and details to the save options class to sign with PdfSaveOptions options = new PdfSaveOptions(); DateTime signingTime = DateTime.Now; options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(certificateHolder, "Test Signing", "Aspose Office", signingTime); // We can use this attribute to set a different hash algorithm options.DigitalSignatureDetails.HashAlgorithm = PdfDigitalSignatureHashAlgorithm.Sha256; Assert.AreEqual("Test Signing", options.DigitalSignatureDetails.Reason); Assert.AreEqual("Aspose Office", options.DigitalSignatureDetails.Location); Assert.AreEqual(signingTime.ToUniversalTime(), options.DigitalSignatureDetails.SignatureDate); doc.Save(ArtifactsDir + "PdfSaveOptions.PdfDigitalSignature.pdf"); //ExEnd }
public void ZoomBehaviour() { //ExStart //ExFor:PdfSaveOptions.PageMode //ExFor:PdfSaveOptions.ZoomBehavior //ExFor:PdfSaveOptions.ZoomFactor //ExFor:PdfPageMode //ExFor:PdfZoomBehavior //ExSummary:Shows how to set the default zooming of an output PDF to 1/4 of default size. // Open a document with multiple paragraphs Document doc = new Document(MyDir + "Rendering.doc"); PdfSaveOptions options = new PdfSaveOptions(); options.ZoomBehavior = PdfZoomBehavior.ZoomFactor; options.ZoomFactor = 25; options.PageMode = PdfPageMode.UseThumbs; // When opening the .pdf with a viewer such as Adobe Acrobat Pro, the zoom level will be at 25% by default, // with thumbnails for each page to the left doc.Save(ArtifactsDir + "PdfSaveOptions.ZoomBehaviour.pdf", options); //ExEnd }
public void SaveAsPdfBookFold() { //ExStart //ExFor:PdfSaveOptions.UseBookFoldPrintingSettings //ExSummary:Shows how to save a document to the PDF format in the form of a book fold. // Open a document with multiple paragraphs Document doc = new Document(MyDir + "Paragraphs.docx"); // Configure both page setup and PdfSaveOptions to create a book fold foreach (Section s in doc.Sections) { s.PageSetup.MultiplePages = MultiplePagesType.BookFoldPrinting; } PdfSaveOptions options = new PdfSaveOptions(); options.UseBookFoldPrintingSettings = true; // In order to make a booklet, we will need to print this document, stack the pages // in the order they come out of the printer and then fold down the middle doc.Save(ArtifactsDir + "PdfSaveOptions.SaveAsPdfBookFold.pdf", options); //ExEnd }
public ActionResult Index(int fid = 0, string token_key = "", int uid = 0) { var PROPOSAL_ID = fid; var USER_ID = uid; var DataUserDownload = db.Database.SqlQuery <VIEW_USERS_PUBLIC>("SELECT * FROM VIEW_USERS_PUBLIC WHERE USER_ID = " + USER_ID + " AND USER_PUBLIC_ACTIVATION_KEY = '" + token_key + "'").FirstOrDefault(); if (DataUserDownload != null) { var Data = db.Database.SqlQuery <VIEW_SNI>("SELECT * FROM VIEW_SNI WHERE SNI_PROPOSAL_ID = " + PROPOSAL_ID).SingleOrDefault(); if (Data.DSNI_DOC_FILETYPE.ToLower() == "docx" || Data.DSNI_DOC_FILETYPE.ToLower() == "doc") { string dataDir = Server.MapPath("~" + Data.DSNI_DOC_FILE_PATH); Stream stream = System.IO.File.OpenRead(dataDir + "" + Data.DSNI_DOC_FILE_NAME + ".DOCX"); var IS_LIMIT_DOWNLOAD = Data.IS_LIMIT_DOWNLOAD; Aspose.Words.Document doc = new Aspose.Words.Document(stream); CustomDocumentProperties props = doc.CustomDocumentProperties; var USER_FULL_NAME = ((Convert.ToString(DataUserDownload.USER_PUBLIC_NAMA_LENGKAP) == "") ? "-" : Convert.ToString(DataUserDownload.USER_PUBLIC_NAMA_LENGKAP)); var ACCESS_NAME = ((Convert.ToString(DataUserDownload.ACCESS_NAME) == "") ? "-" : Convert.ToString(DataUserDownload.ACCESS_NAME)); //query tag doc untuk masyarakat var STYLE_LIST = db.Database.SqlQuery <string>("SELECT * FROM VIEW_SNI_STYLE_GROUP").SingleOrDefault(); var AksesSelect = db.Database.SqlQuery <SYS_DOC_ACCESS_DETAIL_SELECT>("SELECT * FROM SYS_DOC_ACCESS_DETAIL_SELECT WHERE DOC_ACCESS_DETAIL_STYLE_STATUS = 0 AND DOC_ACCESS_DETAIL_ACCESS_ID = 3 ORDER BY SNI_STYLE_SORT ASC").ToList(); var kacang = ((STYLE_LIST != null) ? STYLE_LIST : ""); if (AksesSelect.Count() > 0) { foreach (var i in AksesSelect) { // Get a collection of all paragraph nodes in the document Node[] paragraphs = doc.GetChildNodes(NodeType.Paragraph, true).ToArray(); ArrayList nodesToBeDeleted = new ArrayList(); bool isParagraphFound = false; var SNI_STYLE_VALUE = Convert.ToString(i.SNI_STYLE_VALUE); var SNI_STYLE_NAME = Convert.ToString(i.SNI_STYLE_NAME); foreach (Paragraph paragraph in paragraphs) { if (paragraph.ParagraphFormat.Style.Name == SNI_STYLE_VALUE) { // Filter Heading 1 paras and find one that contains the search string //if (paragraph.Range.Text.ToLower().StartsWith(SNI_STYLE_NAME.ToLower())) if (RemoveSpecialCharacters(paragraph.Range.Text.ToLower()).StartsWith(RemoveSpecialCharacters(SNI_STYLE_NAME).ToLower())) { isParagraphFound = true; // We need to delete all nodes present in between the startPara node // and the next Paragraph with Heading 1 Paragraph startPara = paragraph; nodesToBeDeleted.Add(startPara); startPara = startPara.NextSibling as Paragraph; var styleName = startPara.ParagraphFormat.Style.Name; try { while (!kacang.Contains(startPara.ParagraphFormat.Style.Name) && startPara.ParagraphFormat.Style.Name != "" && startPara.ParagraphFormat.Style.Name != null) { nodesToBeDeleted.Add(startPara); startPara = startPara.NextSibling as Paragraph; } } catch (Exception e) { Console.WriteLine("An error occurred: '{0}'", e); break; } if (isParagraphFound) { break; } } } } // Remove all nodes foreach (Node node in nodesToBeDeleted) { node.Remove(); } } } //END query tag doc untuk masyarakat var DataJmlDownload = db.Database.SqlQuery <SYS_CONFIG>("SELECT * FROM SYS_CONFIG WHERE CONFIG_ID = 10").FirstOrDefault(); var DataWatermark = db.Database.SqlQuery <SYS_CONFIG>("SELECT * FROM SYS_CONFIG WHERE CONFIG_ID = 9").FirstOrDefault(); PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions(); if (IS_LIMIT_DOWNLOAD == 1) { options.PageCount = Convert.ToInt32(DataJmlDownload.CONFIG_VALUE); } var watermarkText = DataWatermark.CONFIG_VALUE; string watermark2Text = "SNI ini di download Oleh " + USER_FULL_NAME + " Sebagai " + ACCESS_NAME; Shape watermark = new Shape(doc, ShapeType.TextPlainText); watermark.TextPath.Text = watermarkText + "\r\n" + watermark2Text; watermark.TextPath.FontFamily = "Arial"; double fontSize = 11; watermark.TextPath.Size = fontSize; watermark.Height = fontSize; watermark.Width = watermarkText.Length * fontSize / 2; watermark.Rotation = 90; watermark.Fill.Color = Color.Pink; // Try LightGray to get more Word-style watermark watermark.StrokeColor = Color.Pink; // Try LightGray to get more Word-style watermark watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.RightMargin; watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page; watermark.WrapType = WrapType.None; watermark.VerticalAlignment = VerticalAlignment.Center; watermark.HorizontalAlignment = HorizontalAlignment.Center; watermark.Fill.Opacity = 0.8; Paragraph watermarkPara = new Paragraph(doc); watermarkPara.AppendChild(watermark); foreach (Section sect in doc.Sections) { InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary); InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst); InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven); } stream.Close(); MemoryStream dstStream = new MemoryStream(); var mime = ""; doc.Save(dstStream, options); mime = "application/pdf"; byte[] byteInfo = dstStream.ToArray(); dstStream.Write(byteInfo, 0, byteInfo.Length); dstStream.Position = 0; Response.ContentType = mime; Response.AddHeader("content-disposition", "attachment; filename=SNI_" + Data.DSNI_DOC_FILE_NAME + ".PDF"); Response.BinaryWrite(byteInfo); Response.End(); return(new FileStreamResult(dstStream, mime)); } else { var filePath = Server.MapPath("~" + Data.DSNI_DOC_FILE_PATH); var fileName = Data.DSNI_DOC_FILE_NAME; var fileType = "PDF"; string dataDir = Server.MapPath("~" + Data.DSNI_DOC_FILE_PATH); Stream stream = System.IO.File.OpenRead(dataDir + "" + Data.DSNI_DOC_FILE_NAME + "." + Data.DSNI_DOC_FILETYPE); Directory.CreateDirectory(Server.MapPath("~/Upload/Temp")); var destPath = Server.MapPath("~/Upload/Temp/"); if (System.IO.File.Exists(destPath + Data.DSNI_DOC_FILE_NAME.Replace("/", "-").Replace(":", "-") + "." + Data.DSNI_DOC_FILETYPE)) { System.IO.File.Delete(destPath + Data.DSNI_DOC_FILE_NAME.Replace("/", "-").Replace(":", "-") + "." + Data.DSNI_DOC_FILETYPE); } System.IO.File.Copy(filePath + fileName + "." + fileType, destPath + Data.DSNI_DOC_FILE_NAME.Replace("/", "-").Replace(":", "-") + "." + fileType); return(Redirect("/Upload/Temp/" + Data.DSNI_DOC_FILE_NAME.Replace("/", "-").Replace(":", "-") + "." + fileType)); } } else { var Link = db.Database.SqlQuery <SYS_LINK>("SELECT * FROM SYS_LINK WHERE LINK_ID = 1 AND LINK_IS_USE = 1 AND LINK_STATUS = 1").SingleOrDefault(); return(Redirect(Link.LINK_NAME + "/auth/index")); } //return Json(new { Data, wew = "SELECT * FROM VIEW_SNI WHERE SNI_PROPOSAL_ID = " + PROPOSAL_ID, dataDir }, JsonRequestBehavior.AllowGet); }