/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfRc4SecurityHandler rc4_40 = new PdfRc4SecurityHandler(); PdfFixedDocument document1 = EncryptRC4(40, rc4_40); PdfRc4SecurityHandler rc4_128 = new PdfRc4SecurityHandler(); PdfFixedDocument document2 = EncryptRC4(128, rc4_128); PdfAesSecurityHandler aes128 = new PdfAesSecurityHandler(); PdfFixedDocument document3 = EncryptAES(128, aes128); PdfAesSecurityHandler aes256 = new PdfAesSecurityHandler(); PdfFixedDocument document4 = EncryptAES(256, aes256); PdfAesSecurityHandler aes256e = new PdfAesSecurityHandler(); aes256e.UseEnhancedPasswordValidation = true; PdfFixedDocument document5 = EncryptAES(256, aes256e); PdfFixedDocument document6 = Decrypt(input); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document1, "xfinium.pdf.sample.encryption.rc4.40bit.pdf", rc4_40), new SampleOutputInfo(document2, "xfinium.pdf.sample.encryption.rc4.128bit.pdf", rc4_128), new SampleOutputInfo(document3, "xfinium.pdf.sample.encryption.aes.128bit.pdf", aes128), new SampleOutputInfo(document4, "xfinium.pdf.sample.encryption.aes.256bit.pdf", aes256), new SampleOutputInfo(document5, "xfinium.pdf.sample.encryption.aes.256bit.enhanced.pdf", aes256e), new SampleOutputInfo(document6, "xfinium.pdf.sample.encryption.decrypted.pdf"), }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream s1, Stream s2) { PdfFixedDocument document = new PdfFixedDocument(); document.DisplayMode = PdfDisplayMode.UseAttachments; PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 16); PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("This document contains 2 file attachments:", helvetica, blackBrush, 50, 50); page.Graphics.DrawString("1. fileattachments.cs.html", helvetica, blackBrush, 50, 70); page.Graphics.DrawString("2. fileattachments.vb.html", helvetica, blackBrush, 50, 90); byte[] fileData1 = new byte[s1.Length]; s1.Read(fileData1, 0, fileData1.Length); PdfDocumentFileAttachment fileAttachment1 = new PdfDocumentFileAttachment(); fileAttachment1.Payload = fileData1; fileAttachment1.FileName = "fileattachments.cs.html"; fileAttachment1.Description = "C# Source Code for FileAttachments sample"; document.FileAttachments.Add(fileAttachment1); byte[] fileData2 = new byte[s2.Length]; s2.Read(fileData2, 0, fileData2.Length); PdfDocumentFileAttachment fileAttachment2 = new PdfDocumentFileAttachment(); fileAttachment2.Payload = fileData1; fileAttachment2.FileName = "fileattachments.vb.html"; fileAttachment2.Description = "VB.NET Source Code for FileAttachments sample"; document.FileAttachments.Add(fileAttachment2); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.fileattachments.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream file1Input, Stream file2Input) { PdfFixedDocument document = new PdfFixedDocument(); // The documents are merged by creating an empty PDF document and appending the file to it. // The outlines from the source file are also included in the merged file. document.AppendFile(file1Input); int count = document.Pages.Count; document.AppendFile(file2Input); // Create outlines that point to each merged file. PdfOutlineItem file1Outline = CreateOutline("First file", document.Pages[0]); document.Outline.Add(file1Outline); PdfOutlineItem file2Outline = CreateOutline("Second file", document.Pages[count]); document.Outline.Add(file2Outline); // Optionally we can add a new page at the beginning of the merged document. PdfPage page = new PdfPage(); document.Pages.Insert(0, page); PdfOutlineItem blankPageOutline = CreateOutline("Blank page", page); document.Outline.Insert(0, blankPageOutline); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.documentappend.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfFixedDocument document = new PdfFixedDocument(input); PdfContentRedactor crText = new PdfContentRedactor(document.Pages[0]); // Redact a rectangular area of 200*100 points and leave the redacted area uncovered. crText.RedactArea(new PdfVisualRectangle(50, 50, 200, 100)); // Redact a rectangular area of 200*100 points and mark the redacted area with red. crText.RedactArea(new PdfVisualRectangle(50, 350, 200, 100), PdfRgbColor.Red); PdfContentRedactor crImages = new PdfContentRedactor(document.Pages[2]); // Initialize the bulk redaction. crImages.BeginRedaction(); // Prepare for redaction a rectangular area of 500*100 points and leave the redacted area uncovered. crImages.RedactArea(new PdfVisualRectangle(50, 50, 500, 100)); // Prepare for redaction a rectangular area of 200*100 points and mark the redacted area with red. crImages.RedactArea(new PdfVisualRectangle(50, 350, 500, 100), PdfRgbColor.Red); // When images are redacted, the cleared pixels are set to 0. Depending on image colorspace the redacted area can appear black or colored. // Finish the redaction crImages.ApplyRedaction(); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.redaction.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfFile file = new PdfFile(input); PdfPageContent[] content = file.ExtractPageContent(0, file.PageCount - 1); file = null; PdfFixedDocument document = new PdfFixedDocument(); PdfPage page1 = document.Pages.Add(); // Draw the same page content 4 times on the new page, the content is scaled to half and flipped. page1.Graphics.DrawFormXObject(content[0], 0, 0, page1.Width / 2, page1.Height / 2); page1.Graphics.DrawFormXObject(content[0], page1.Width / 2, 0, page1.Width / 2, page1.Height / 2, 0, PdfFlipDirection.VerticalFlip); page1.Graphics.DrawFormXObject(content[0], 0, page1.Height / 2, page1.Width / 2, page1.Height / 2, 0, PdfFlipDirection.HorizontalFlip); page1.Graphics.DrawFormXObject(content[0], page1.Width / 2, page1.Height / 2, page1.Width / 2, page1.Height / 2, 0, PdfFlipDirection.VerticalFlip | PdfFlipDirection.HorizontalFlip); PdfPage page2 = document.Pages.Add(); // Draw 3 pages on the new page. page2.Graphics.DrawFormXObject(content[0], 0, 0, page2.Width / 2, page2.Height / 2); page2.Graphics.DrawFormXObject(content[1], page2.Width / 2, 0, page2.Width / 2, page2.Height / 2); page2.Graphics.DrawFormXObject(content[2], 0, page2.Height, page2.Height / 2, page2.Width, 90); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pageimposition.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream iccInput, Stream ttfInput) { PdfFixedDocument document = new PdfFixedDocument(); // Setup the document by creating a PDF/A output intent, based on a RGB ICC profile, // and document information and metadata PdfIccColorSpace icc = new PdfIccColorSpace(); byte[] profilePayload = new byte[iccInput.Length]; iccInput.Read(profilePayload, 0, profilePayload.Length); icc.IccProfile = profilePayload; PdfOutputIntent oi = new PdfOutputIntent(); oi.Type = PdfOutputIntentType.PdfA1; oi.Info = "sRGB IEC61966-2.1"; oi.OutputConditionIdentifier = "Custom"; oi.DestinationOutputProfile = icc; document.OutputIntents = new PdfOutputIntentCollection(); document.OutputIntents.Add(oi); document.DocumentInformation = new PdfDocumentInformation(); document.DocumentInformation.Author = "XFINIUM Software"; document.DocumentInformation.Title = "XFINIUM.PDF PDF/A-1B Demo"; document.DocumentInformation.Creator = "XFINIUM.PDF PDF/A-1B Demo"; document.DocumentInformation.Producer = "XFINIUM.PDF"; document.DocumentInformation.Keywords = "pdf/a"; document.DocumentInformation.Subject = "PDF/A-1B Sample produced by XFINIUM.PDF"; document.XmpMetadata = new PdfXmpMetadata(); PdfPage page = document.Pages.Add(); page.Rotation = 90; // All fonts must be embedded in a PDF/A document. PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions(); sao.Font = new PdfAnsiTrueTypeFont(ttfInput, 24, true); sao.Brush = new PdfBrush(new PdfRgbColor(0, 0, 128)); PdfStringLayoutOptions slo = new PdfStringLayoutOptions(); slo.HorizontalAlign = PdfStringHorizontalAlign.Center; slo.VerticalAlign = PdfStringVerticalAlign.Bottom; slo.X = page.Width / 2; slo.Y = page.Height / 2 - 10; page.Graphics.DrawString("XFINIUM.PDF", sao, slo); slo.Y = page.Height / 2 + 10; slo.VerticalAlign = PdfStringVerticalAlign.Top; sao.Font.Size = 16; page.Graphics.DrawString("This is a sample PDF/A document that shows the PDF/A capabilities in XFINIUM.PDF library", sao, slo); // The document is formatted as PDF/A using the PdfAFormatter class: // PdfAFormatter.Save(document, outputStream, PdfAFormat.PdfA1b); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pdfa.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfFixedDocument document = new PdfFixedDocument(); PdfPage page = document.Pages.Add(); PdfSvgDrawing svg = new PdfSvgDrawing(input); page.Graphics.DrawFormXObject(svg, 20, 20, page.Width - 40, page.Width - 40); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.svgtopdf.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { // Load the input file. PdfFixedDocument document = new PdfFixedDocument(input); PdfConvertToGrayTransform grayTransform = new PdfConvertToGrayTransform(); PdfPageTransformer pageTransformer = new PdfPageTransformer(document.Pages[3]); pageTransformer.ApplyTransform(grayTransform); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.grayscaleconversion.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfFixedDocument document = new PdfFixedDocument(); PdfTiffImage tiff = new PdfTiffImage(input); for (int i = 0; i < tiff.FrameCount; i++) { tiff.ActiveFrame = i; PdfPage page = document.Pages.Add(); page.Graphics.DrawImage(tiff, 0, 0, page.Width, page.Height); } SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.tifftopdf.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { // Load the input file. PdfFixedDocument document = new PdfFixedDocument(input); PdfReplaceImageTransform replaceImageTransform = new PdfReplaceImageTransform(); replaceImageTransform.ReplaceImage += new EventHandler <PdfReplaceImageEventArgs>(HandleReplaceImage); PdfPageTransformer pageTransformer = new PdfPageTransformer(document.Pages[2]); pageTransformer.ApplyTransform(replaceImageTransform); replaceImageTransform.ReplaceImage -= new EventHandler <PdfReplaceImageEventArgs>(HandleReplaceImage); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.removereplaceimages.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { // The input file is split by extracting pages from source file and inserting them in new empty PDF documents. PdfFile file = new PdfFile(input); SampleOutputInfo[] output = new SampleOutputInfo[file.PageCount]; for (int i = 0; i < file.PageCount; i++) { PdfFixedDocument document = new PdfFixedDocument(); PdfPage page = file.ExtractPage(i); document.Pages.Add(page); output[i] = new SampleOutputInfo(document, string.Format("xfinium.pdf.sample.documentsplit.{0}.pdf", i + 1)); } return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfPage page = document.Pages.Add(); DrawTextLines(page, helveticaBold); page = document.Pages.Add(); DrawTextWrap(page, helveticaBold); page = document.Pages.Add(); DrawTextRenderingModes(page, helveticaBold); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.text.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> /// <param name="stream"></param> public static SampleOutputInfo[] Run(Stream stream) { PdfFixedDocument document = new PdfFixedDocument(stream); (document.Form.Fields["firstname"] as PdfTextBoxField).Text = "John"; (document.Form.Fields["lastname"] as PdfTextBoxField).Value = "Doe"; (document.Form.Fields["sex"].Widgets[0] as PdfRadioButtonWidget).Checked = true; (document.Form.Fields["firstcar"] as PdfComboBoxField).SelectedIndex = 0; (document.Form.Fields["secondcar"] as PdfListBoxField).SelectedIndex = 1; (document.Form.Fields["agree"] as PdfCheckBoxField).Checked = true; document.Form.FlattenFields(); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formfill.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> /// <param name="iccStream"></param> public static SampleOutputInfo[] Run(Stream iccStream) { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helveticaBoldTitle = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfStandardFont helveticaSection = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); PdfPage page = document.Pages.Add(); DrawLines(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawRectangles(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawRoundRectangles(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawEllipses(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawArcsAndPies(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawBezierCurves(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawAffineTransformations(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawColorsAndColorSpaces(page, helveticaBoldTitle, helveticaSection, iccStream); page = document.Pages.Add(); DrawShadings(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawPatterns(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawFormXObjects(page, helveticaBoldTitle, helveticaSection); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.vectorgraphics.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> /// <param name="imageStream"></param> /// <param name="cmykImageStream"></param> /// <param name="softMaskStream"></param> /// <param name="stencilMaskStream"></param> public static SampleOutputInfo[] Run(Stream imageStream, Stream cmykImageStream, Stream softMaskStream, Stream stencilMaskStream) { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helveticaBoldTitle = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfStandardFont helveticaSection = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); PdfPage page = document.Pages.Add(); DrawImages(page, imageStream, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawImageMasks(page, imageStream, softMaskStream, stencilMaskStream, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawCmykTiff(page, cmykImageStream, helveticaBoldTitle); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.images.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { // Load the input file. PdfFixedDocument document = new PdfFixedDocument(input); DrawWatermarkUnderPageContent(document.Pages[0]); DrawWatermarkOverPageContent(document.Pages[1]); DrawWatermarkWithTransparency(document.Pages[2]); // Compress the page graphic content. for (int i = 0; i < document.Pages.Count; i++) { document.Pages[i].Graphics.CompressAndClose(); } SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.watermarks.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { // Load the input file. PdfFixedDocument document = new PdfFixedDocument(input); ExtractTextAndHighlight(document); ExtractTextAndHighlightGlyphs(document); ExtractImagesAndHighlight(document); // Compress the page graphic content. for (int i = 0; i < document.Pages.Count; i++) { document.Pages[i].Graphics.CompressAndClose(); } SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.contentextraction.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream ttfStream) { PdfFixedDocument document = new PdfFixedDocument(); PdfPage page = document.Pages.Add(); DrawStandardFonts(page); page = document.Pages.Add(); DrawStandardCjkFonts(page); page = document.Pages.Add(); DrawTrueTypeFonts(page, ttfStream); page = document.Pages.Add(); DisableTextCopy(page, ttfStream); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.fonts.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { // Load the input file. PdfFixedDocument document = new PdfFixedDocument(input); PdfBatesNumberAppearance bna = new PdfBatesNumberAppearance(); bna.Location = new PdfPoint(25, 5); bna.Brush = new PdfBrush(PdfRgbColor.DarkRed); PdfBatesNumberProvider bnp = new PdfBatesNumberProvider(); bnp.Prefix = "XFINIUM"; bnp.Suffix = "PDF"; bnp.StartNumber = 1; PdfBatesNumber.WriteBatesNumber(document, bnp, bna); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.batesnumbers.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfFixedDocument document = new PdfFixedDocument(input); PdfContentExtractor ce = new PdfContentExtractor(document.Pages[0]); // Simple search. PdfTextSearchResultCollection searchResults = ce.SearchText("at"); HighlightSearchResults(document.Pages[0], searchResults, PdfRgbColor.Red); // Whole words search. searchResults = ce.SearchText("at", PdfTextSearchOptions.WholeWordSearch); HighlightSearchResults(document.Pages[0], searchResults, PdfRgbColor.Green); // Regular expression search, find all words that start with uppercase. searchResults = ce.SearchText("[A-Z][a-z]*", PdfTextSearchOptions.RegExSearch); HighlightSearchResults(document.Pages[0], searchResults, PdfRgbColor.Blue); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.searchtext.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream flashStream, Stream u3dStream) { // Create a PDF document with 10 pages. PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12); CreateTextAnnotations(document, helvetica); CreateSquareCircleAnnotations(document, helvetica); CreateFileAttachmentAnnotations(document, helvetica); CreateInkAnnotations(document, helvetica); CreateLineAnnotations(document, helvetica); CreatePolygonAnnotations(document, helvetica); CreatePolylineAnnotations(document, helvetica); CreateRubberStampAnnotations(document, helvetica); CreateTextMarkupAnnotations(document, helvetica); CreateRichMediaAnnotations(document, helvetica, flashStream); Create3DAnnotations(document, helvetica, u3dStream); CreateRedactionAnnotations(document, helvetica, u3dStream); // Compress the page graphic content. for (int i = 0; i < document.Pages.Count; i++) { document.Pages[i].Graphics.CompressAndClose(); } SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.annotations.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); document.Pages.Add(); // Display the document in full screen mode. document.DisplayMode = PdfDisplayMode.FullScreen; // Fill the document information. document.DocumentInformation = new PdfDocumentInformation(); document.DocumentInformation.Author = "Xfinium Software"; document.DocumentInformation.CreationDate = DateTime.Now; document.DocumentInformation.ModifyDate = DateTime.Now; document.DocumentInformation.Creator = "Xfinium.Pdf DocumentProperties sample"; document.DocumentInformation.Producer = "Xfinium.Pdf"; document.DocumentInformation.Title = "Xfinium.Pdf DocumentProperties sample"; document.DocumentInformation.Subject = "Xfinium.Pdf sample code"; document.DocumentInformation.Keywords = "xfinium.pdf,pdf,sample"; // Set custom metadata in the XMP metadata. document.XmpMetadata = new PdfXmpMetadata(); // This custom metadata will appear as a child of 'xmpmeta' root node. document.XmpMetadata.Metadata = "<custom>Custom metadata</custom>"; // Set the viewer preferences. document.ViewerPreferences = new PdfViewerPreferences(); document.ViewerPreferences.CenterWindow = true; document.ViewerPreferences.DisplayDocumentTitle = true; document.ViewerPreferences.HideMenubar = true; document.ViewerPreferences.HideToolbar = true; document.ViewerPreferences.HideWindowUI = true; document.ViewerPreferences.PrintScaling = PdfPrintScaling.None; // Set the PDF version. document.PdfVersion = PdfVersion.Version15; SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.documentproperties.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfFile file = new PdfFile(input); PdfFixedDocument document = new PdfFixedDocument(); PdfPage page = document.Pages.Add(); PdfPageOptionalContent oc1 = file.ExtractPageOptionalContentGroup(4, "1"); page.Graphics.DrawFormXObject(oc1, 0, 0, page.Width / 2, page.Height / 2); PdfPageOptionalContent oc2 = file.ExtractPageOptionalContentGroup(4, "2"); page.Graphics.DrawFormXObject(oc2, page.Width / 2, 0, page.Width / 2, page.Height / 2); PdfPageOptionalContent oc3 = file.ExtractPageOptionalContentGroup(4, "3"); page.Graphics.DrawFormXObject(oc3, 0, page.Height / 2, page.Width / 2, page.Height / 2); PdfPageOptionalContent oc4 = file.ExtractPageOptionalContentGroup(4, "4"); page.Graphics.DrawFormXObject(oc4, page.Width / 2, page.Height / 2, page.Width / 2, page.Height / 2); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.optionalcontentextraction.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { // Create a PDF document with 10 pages. PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 216); PdfBrush blackBrush = new PdfBrush(); for (int i = 0; i < 10; i++) { PdfPage page = document.Pages.Add(); page.Graphics.DrawString((i + 1).ToString(), helvetica, blackBrush, 5, 5); } CreateNamedActions(document, helvetica); CreateGoToActions(document, helvetica); CreateRemoteGoToActions(document, helvetica); CreateLaunchActions(document, helvetica); CreateUriActions(document, helvetica); CreateJavaScriptActions(document, helvetica); CreateDocumentActions(document); // Compress the page graphic content. for (int i = 0; i < document.Pages.Count; i++) { document.Pages[i].Graphics.CompressAndClose(); } SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.actions.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); document.OptionalContentProperties = new PdfOptionalContentProperties(); PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18); PdfBrush blackBrush = new PdfBrush(); PdfBrush greenBrush = new PdfBrush(PdfRgbColor.DarkGreen); PdfBrush yellowBrush = new PdfBrush(PdfRgbColor.Yellow); PdfPen bluePen = new PdfPen(PdfRgbColor.DarkBlue, 5); PdfPen redPen = new PdfPen(PdfRgbColor.DarkRed, 5); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Simple optional content: the green rectangle", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage1 = new PdfOptionalContentGroup(); ocgPage1.Name = "Page 1 - Green Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage1); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 100, 570, 400); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Multipart optional content: the green rectangles", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage2 = new PdfOptionalContentGroup(); ocgPage2.Name = "Page 2 - Green Rectangles"; page.Graphics.BeginOptionalContentGroup(ocgPage2); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage2); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Imbricated optional content: the green and yellow rectangles", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage31 = new PdfOptionalContentGroup(); ocgPage31.Name = "Page 3 - Green Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage31); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 100, 570, 600); PdfOptionalContentGroup ocgPage32 = new PdfOptionalContentGroup(); ocgPage32.Name = "Page 3 - Yellow Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage32); page.Graphics.DrawRectangle(redPen, yellowBrush, 100, 200, 400, 300); page.Graphics.EndOptionalContentGroup(); // ocgPage32 page.Graphics.EndOptionalContentGroup(); // ocgPage31 page = document.Pages.Add(); page.Graphics.DrawString("Multipage optional content: the green rectangles on page 4 & 5", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage45 = new PdfOptionalContentGroup(); ocgPage45.Name = "Page 4 & 5 - Green Rectangles"; page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Multipage optional content: continued", helveticaBold, blackBrush, 20, 50); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); // Build the display tree for the optional content, // how its structure and relationships between optional content groups are presented to the user. PdfOptionalContentDisplayTreeNode ocgPage1Node = new PdfOptionalContentDisplayTreeNode(ocgPage1); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node); PdfOptionalContentDisplayTreeNode ocgPage2Node = new PdfOptionalContentDisplayTreeNode(ocgPage2); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage2Node); PdfOptionalContentDisplayTreeNode ocgPage31Node = new PdfOptionalContentDisplayTreeNode(ocgPage31); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage31Node); PdfOptionalContentDisplayTreeNode ocgPage32Node = new PdfOptionalContentDisplayTreeNode(ocgPage32); ocgPage31Node.Nodes.Add(ocgPage32Node); PdfOptionalContentDisplayTreeNode ocgPage45Node = new PdfOptionalContentDisplayTreeNode(ocgPage45); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage45Node); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.optionalcontent.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfBrush brush = new PdfBrush(); PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); PdfFixedDocument document = new PdfFixedDocument(input); PdfContentExtractor ce = new PdfContentExtractor(document.Pages[0]); PdfVisualObjectCollection voc = ce.ExtractVisualObjects(false); PdfPath contour = null; for (int i = 0; i < voc.Count; i++) { switch (voc[i].Type) { case PdfVisualObjectType.Image: PdfImageVisualObject ivo = voc[i] as PdfImageVisualObject; contour = new PdfPath(); contour.StartSubpath(ivo.Image.ImageCorners[0].X - 5, ivo.Image.ImageCorners[0].Y + 5); contour.AddLineTo(ivo.Image.ImageCorners[1].X + 5, ivo.Image.ImageCorners[1].Y + 5); contour.AddLineTo(ivo.Image.ImageCorners[2].X + 5, ivo.Image.ImageCorners[2].Y - 5); contour.AddLineTo(ivo.Image.ImageCorners[3].X - 5, ivo.Image.ImageCorners[3].Y - 5); contour.CloseSubpath(); document.Pages[0].Graphics.DrawPath(redPen, contour); document.Pages[0].Graphics.DrawString("Image", helvetica, brush, ivo.Image.ImageCorners[0].X - 5, ivo.Image.ImageCorners[0].Y + 5); break; case PdfVisualObjectType.Text: PdfTextVisualObject tvo = voc[i] as PdfTextVisualObject; contour = new PdfPath(); contour.StartSubpath(tvo.TextFragment.FragmentCorners[0].X - 5, tvo.TextFragment.FragmentCorners[0].Y + 5); contour.AddLineTo(tvo.TextFragment.FragmentCorners[1].X + 5, tvo.TextFragment.FragmentCorners[1].Y + 5); contour.AddLineTo(tvo.TextFragment.FragmentCorners[2].X + 5, tvo.TextFragment.FragmentCorners[2].Y - 5); contour.AddLineTo(tvo.TextFragment.FragmentCorners[3].X - 5, tvo.TextFragment.FragmentCorners[3].Y - 5); contour.CloseSubpath(); document.Pages[0].Graphics.DrawPath(redPen, contour); document.Pages[0].Graphics.DrawString("Text", helvetica, brush, tvo.TextFragment.FragmentCorners[0].X - 5, tvo.TextFragment.FragmentCorners[0].Y + 5); break; case PdfVisualObjectType.Path: PdfPathVisualObject pvo = voc[i] as PdfPathVisualObject; // Examine all the path points and determine the minimum rectangle that bounds the path. double minX = 999999, minY = 999999, maxX = -999999, maxY = -999999; for (int j = 0; j < pvo.PathItems.Count; j++) { PdfPathItem pi = pvo.PathItems[j]; if (pi.Points != null) { for (int k = 0; k < pi.Points.Length; k++) { if (minX >= pi.Points[k].X) { minX = pi.Points[k].X; } if (minY >= pi.Points[k].Y) { minY = pi.Points[k].Y; } if (maxX <= pi.Points[k].X) { maxX = pi.Points[k].X; } if (maxY <= pi.Points[k].Y) { maxY = pi.Points[k].Y; } } } } contour = new PdfPath(); contour.StartSubpath(minX - 5, minY - 5); contour.AddLineTo(maxX + 5, minY - 5); contour.AddLineTo(maxX + 5, maxY + 5); contour.AddLineTo(minX - 5, maxY + 5); contour.CloseSubpath(); document.Pages[0].Graphics.DrawPath(redPen, contour); document.Pages[0].Graphics.DrawString("Path", helvetica, brush, minX - 5, maxY + 5); // Skip the rest of path objects, they are the evaluation message i = voc.Count; break; } } SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pageobjects.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> /// <param name="stream"></param> public static SampleOutputInfo[] Run() { // Create the pdf document PdfFixedDocument document = new PdfFixedDocument(); // Create a new page in the document PdfPage page = document.Pages.Add(); PdfBrush brush = new PdfBrush(PdfRgbColor.DarkRed); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 36); page.Graphics.DrawString("Hello World", helvetica, brush, 100, 100); PdfContentStream cs = new PdfContentStream(page.Graphics); // Sets the stroke and fill colorspaces to DeviceRGB cs.SetStrokeColorSpace(new PdfRgbColorSpace()); cs.SetFillColorSpace(new PdfRgbColorSpace()); // Set stroke color to blue cs.SetStrokeColor(new double[] { 0, 0, 1 }); // Set fill color to green cs.SetFillColor(new double[] { 0, 1, 0 }); // Draw a line from (0, 0) to (page.Width/2, page.Height/2) // It will be drawn from top left corner to center of the page. cs.MoveTo(0, 0); cs.LineTo(page.Width / 2, page.Height / 2); cs.StrokePath(); // Begin a text section cs.BeginText(); cs.SetTextRendering(PdfTextRenderingMode.FillText); cs.SetTextMatrix(1, 0, 0, 1, 100, 150); cs.SetTextFontAndSize(helvetica, helvetica.Size); // This text will appear inverted because the coordinate system is in visual mode. byte[] binaryText = helvetica.EncodeString("Hello World"); cs.ShowText(new PdfCosBinaryString(binaryText)); cs.EndText(); // Reset coordinate system and the current graphics state to default PDF cs.ResetPdfCoordinateSystem(); // Sets the stroke and fill colorspaces to DeviceRGB cs.SetStrokeColorSpace(new PdfRgbColorSpace()); cs.SetFillColorSpace(new PdfRgbColorSpace()); // Set stroke color to blue cs.SetStrokeColor(new double[] { 0, 0, 1 }); // Set fill color to green cs.SetFillColor(new double[] { 0, 1, 0 }); // Draw a line from (0, 0) to (page.Width/2, page.Height/2) // It will be drawn from bottom left corner to center of the page because the coordinate system has been reset to default PDF. cs.MoveTo(0, 0); cs.LineTo(page.Width / 2, page.Height / 2); cs.StrokePath(); // Draw the text again cs.BeginText(); cs.SetTextRendering(PdfTextRenderingMode.FillText); cs.SetTextMatrix(1, 0, 0, 1, 100, 150); cs.SetTextFontAndSize(helvetica, helvetica.Size); // This text will appear ok. binaryText = helvetica.EncodeString("Hello World"); cs.ShowText(new PdfCosBinaryString(binaryText)); cs.EndText(); // Restore the visual coordinate system cs.RestoreVisualCoordinateSystem(); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.contentstream.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { // Create the pdf document PdfFixedDocument document = new PdfFixedDocument(); // Create a new page in the document PdfPage page = document.Pages.Add(); PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1); PdfPen redPen = new PdfPen(PdfRgbColor.Red, 4); PdfPen greenPen = new PdfPen(PdfRgbColor.Green, 2); PdfBrush blackBrush = new PdfBrush(PdfRgbColor.Black); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 16); // Draw viewport border. page.Graphics.DrawRectangle(blackPen, 50, 50, 500, 500); // Draw the line to be measured. page.Graphics.DrawLine(greenPen, 70, 70, 530, 530); // Draw point A (line start) in the viewport. page.Graphics.DrawLine(redPen, 60, 70, 80, 70); page.Graphics.DrawLine(redPen, 70, 60, 70, 80); // Draw point B (line end) in the viewport. page.Graphics.DrawLine(redPen, 520, 530, 540, 530); page.Graphics.DrawLine(redPen, 530, 520, 530, 540); page.Graphics.DrawString("A", helvetica, blackBrush, 85, 65); page.Graphics.DrawString("B", helvetica, blackBrush, 505, 525); page.Graphics.DrawString("Viewport", helvetica, blackBrush, 50, 560); helvetica.Size = 10; page.Graphics.DrawString( "Open the file with Adobe Acrobat and measure the distance from A to B using the Distance tool.", helvetica, blackBrush, 50, 580); page.Graphics.DrawString("The measured distance should be 9 mi 186 ft 1 1/4 in.", helvetica, blackBrush, 50, 590); // Create a viewport that matches the rectangle above. PdfViewport vp = new PdfViewport(); vp.Name = "Sample viewport"; PdfPoint ll = page.ConvertVisualPointToStandardPoint(new PdfPoint(50, 50)); PdfPoint ur = page.ConvertVisualPointToStandardPoint(new PdfPoint(550, 550)); vp.Bounds = new PdfStandardRectangle(ll, ur); // Add the viewport to the page page.Viewports = new PdfViewportCollection(); page.Viewports.Add(vp); // Create a rectilinear measure for the viewport (CAD drawing for example). PdfRectilinearMeasure rlm = new PdfRectilinearMeasure(); // Attach the measure to the viewport. vp.Measure = rlm; // Set the measure scale: 1 inch (72 points) in PDF corresponds to 1 mile rlm.ScaleRatio = "1 in = 1 mi"; // Create a number format that controls the display of units for X axis. PdfNumberFormat xNumberFormat = new PdfNumberFormat(); xNumberFormat.MeasureUnit = "mi"; xNumberFormat.ConversionFactor = 1 / 72.0; // Conversion from user space units to miles xNumberFormat.FractionDisplay = PdfFractionDisplay.Decimal; xNumberFormat.Precision = 100000; rlm.X = new PdfNumberFormatCollection(); rlm.X.Add(xNumberFormat); // Create a chain of number formats that control the display of units for distance. rlm.Distance = new PdfNumberFormatCollection(); PdfNumberFormat miNumberFormat = new PdfNumberFormat(); miNumberFormat.MeasureUnit = "mi"; miNumberFormat.ConversionFactor = 1; // Initial unit is miles; no conversion needed rlm.Distance.Add(miNumberFormat); PdfNumberFormat ftNumberFormat = new PdfNumberFormat(); ftNumberFormat.MeasureUnit = "ft"; ftNumberFormat.ConversionFactor = 5280; // Conversion from miles to feet rlm.Distance.Add(ftNumberFormat); PdfNumberFormat inNumberFormat = new PdfNumberFormat(); inNumberFormat.MeasureUnit = "in"; inNumberFormat.ConversionFactor = 12; // Conversion from feet to inches inNumberFormat.FractionDisplay = PdfFractionDisplay.Fraction; inNumberFormat.Denominator = 8; // Fractions of inches rounded to nearest 1/8 rlm.Distance.Add(inNumberFormat); // Create a number format that controls the display of units area. PdfNumberFormat areaNumberFormat = new PdfNumberFormat(); areaNumberFormat.MeasureUnit = "acres"; areaNumberFormat.ConversionFactor = 640; // Conversion from square miles to acres rlm.Area = new PdfNumberFormatCollection(); rlm.Area.Add(xNumberFormat); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.measurements.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12); PdfBrush brush = new PdfBrush(); PdfPage page = document.Pages.Add(); // First name page.Graphics.DrawString("First name:", helvetica, brush, 50, 50); PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname"); page.Fields.Add(firstNameTextBox); firstNameTextBox.Widgets[0].Font = helvetica; firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20); firstNameTextBox.Widgets[0].BorderColor = PdfRgbColor.Black; firstNameTextBox.Widgets[0].BorderWidth = 1; // Last name page.Graphics.DrawString("Last name:", helvetica, brush, 50, 80); PdfTextBoxField lastNameTextBox = new PdfTextBoxField("lastname"); page.Fields.Add(lastNameTextBox); lastNameTextBox.Widgets[0].Font = helvetica; lastNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 75, 200, 20); lastNameTextBox.Widgets[0].BorderColor = PdfRgbColor.Black; lastNameTextBox.Widgets[0].BorderWidth = 1; // Sex page.Graphics.DrawString("Sex:", helvetica, brush, 50, 110); PdfRadioButtonField sexRadioButton = new PdfRadioButtonField("sex"); PdfRadioButtonWidget maleRadioItem = new PdfRadioButtonWidget(); sexRadioButton.Widgets.Add(maleRadioItem); PdfRadioButtonWidget femaleRadioItem = new PdfRadioButtonWidget(); sexRadioButton.Widgets.Add(femaleRadioItem); page.Fields.Add(sexRadioButton); page.Graphics.DrawString("Male", helvetica, brush, 180, 110); maleRadioItem.ExportValue = "M"; maleRadioItem.CheckStyle = PdfCheckStyle.Circle; maleRadioItem.VisualRectangle = new PdfVisualRectangle(150, 105, 20, 20); maleRadioItem.BorderColor = PdfRgbColor.Black; maleRadioItem.BorderWidth = 1; page.Graphics.DrawString("Female", helvetica, brush, 280, 110); femaleRadioItem.ExportValue = "F"; femaleRadioItem.CheckStyle = PdfCheckStyle.Circle; femaleRadioItem.VisualRectangle = new PdfVisualRectangle(250, 105, 20, 20); femaleRadioItem.BorderColor = PdfRgbColor.Black; femaleRadioItem.BorderWidth = 1; // First car page.Graphics.DrawString("First car:", helvetica, brush, 50, 140); PdfComboBoxField firstCarList = new PdfComboBoxField("firstcar"); firstCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes")); firstCarList.Items.Add(new PdfListItem("BMW", "BMW")); firstCarList.Items.Add(new PdfListItem("Audi", "Audi")); firstCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen")); firstCarList.Items.Add(new PdfListItem("Porsche", "Porsche")); firstCarList.Items.Add(new PdfListItem("Honda", "Honda")); firstCarList.Items.Add(new PdfListItem("Toyota", "Toyota")); firstCarList.Items.Add(new PdfListItem("Lexus", "Lexus")); firstCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti")); firstCarList.Items.Add(new PdfListItem("Acura", "Acura")); page.Fields.Add(firstCarList); firstCarList.Widgets[0].Font = helvetica; firstCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 135, 200, 20); firstCarList.Widgets[0].BorderColor = PdfRgbColor.Black; firstCarList.Widgets[0].BorderWidth = 1; // Second car page.Graphics.DrawString("Second car:", helvetica, brush, 50, 170); PdfListBoxField secondCarList = new PdfListBoxField("secondcar"); secondCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes")); secondCarList.Items.Add(new PdfListItem("BMW", "BMW")); secondCarList.Items.Add(new PdfListItem("Audi", "Audi")); secondCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen")); secondCarList.Items.Add(new PdfListItem("Porsche", "Porsche")); secondCarList.Items.Add(new PdfListItem("Honda", "Honda")); secondCarList.Items.Add(new PdfListItem("Toyota", "Toyota")); secondCarList.Items.Add(new PdfListItem("Lexus", "Lexus")); secondCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti")); secondCarList.Items.Add(new PdfListItem("Acura", "Acura")); page.Fields.Add(secondCarList); secondCarList.Widgets[0].Font = helvetica; secondCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 165, 200, 60); secondCarList.Widgets[0].BorderColor = PdfRgbColor.Black; secondCarList.Widgets[0].BorderWidth = 1; // I agree page.Graphics.DrawString("I agree:", helvetica, brush, 50, 240); PdfCheckBoxField agreeCheckBox = new PdfCheckBoxField("agree"); page.Fields.Add(agreeCheckBox); agreeCheckBox.Widgets[0].Font = helvetica; (agreeCheckBox.Widgets[0] as PdfCheckWidget).ExportValue = "YES"; (agreeCheckBox.Widgets[0] as PdfCheckWidget).CheckStyle = PdfCheckStyle.Check; agreeCheckBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 235, 20, 20); agreeCheckBox.Widgets[0].BorderColor = PdfRgbColor.Black; agreeCheckBox.Widgets[0].BorderWidth = 1; // Sign here page.Graphics.DrawString("Sign here:", helvetica, brush, 50, 270); PdfSignatureField signHereField = new PdfSignatureField("signhere"); page.Fields.Add(signHereField); signHereField.Widgets[0].Font = helvetica; signHereField.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 265, 200, 60); // Submit form PdfPushButtonField submitBtn = new PdfPushButtonField("submit"); page.Fields.Add(submitBtn); submitBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 45, 150, 30); (submitBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Submit form"; submitBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray; PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction(); submitFormAction.DataFormat = PdfSubmitDataFormat.FDF; submitFormAction.Fields.Add("firstname"); submitFormAction.Fields.Add("lastname"); submitFormAction.Fields.Add("sex"); submitFormAction.Fields.Add("firstcar"); submitFormAction.Fields.Add("secondcar"); submitFormAction.Fields.Add("agree"); submitFormAction.Fields.Add("signhere"); submitFormAction.SubmitFields = true; submitFormAction.Url = "http://www.xfiniumsoft.com/"; submitBtn.Widgets[0].MouseUp = submitFormAction; // Reset form PdfPushButtonField resetBtn = new PdfPushButtonField("reset"); page.Fields.Add(resetBtn); resetBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 85, 150, 30); (resetBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Reset form"; resetBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray; PdfResetFormAction resetFormAction = new PdfResetFormAction(); resetBtn.Widgets[0].MouseUp = resetFormAction; // Print form PdfPushButtonField printBtn = new PdfPushButtonField("print"); page.Fields.Add(printBtn); printBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 125, 150, 30); (printBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Print form"; printBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray; PdfJavaScriptAction printAction = new PdfJavaScriptAction(); printAction.Script = "this.print(true);\n"; printBtn.Widgets[0].MouseUp = printAction; SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formgenerator.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); document.DisplayMode = PdfDisplayMode.UseOutlines; PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 216); PdfBrush blackBrush = new PdfBrush(); for (int i = 0; i < 10; i++) { PdfPage page = document.Pages.Add(); page.Graphics.DrawString((i + 1).ToString(), helvetica, blackBrush, 50, 50); } PdfOutlineItem root = new PdfOutlineItem(); root.Title = "Contents"; root.VisualStyle = PdfOutlineItemVisualStyle.Bold; root.Color = new PdfRgbColor(255, 0, 0); document.Outline.Add(root); for (int i = 0; i < document.Pages.Count; i++) { // Create a destination to target page. PdfPageDirectDestination pageDestination = new PdfPageDirectDestination(); pageDestination.Page = document.Pages[i]; pageDestination.Top = 0; pageDestination.Left = 0; // Inherit current zoom pageDestination.Zoom = 0; // Create a go to action to be executed when the outline is clicked, // the go to action goes to specified destination. PdfGoToAction gotoPage = new PdfGoToAction(); gotoPage.Destination = pageDestination; // Create the outline in the table of contents PdfOutlineItem outline = new PdfOutlineItem(); outline.Title = string.Format("Go to page {0}", i + 1); outline.VisualStyle = PdfOutlineItemVisualStyle.Italic; outline.Action = gotoPage; root.Items.Add(outline); } root.Expanded = true; // Create an outline that will launch a link in the browser. PdfUriAction uriAction = new PdfUriAction(); uriAction.URI = "http://www.xfiniumsoft.com/"; PdfOutlineItem webOutline = new PdfOutlineItem(); webOutline.Title = "http://www.xfiniumsoft.com/"; webOutline.Color = new PdfRgbColor(0, 0, 255); webOutline.Action = uriAction; document.Outline.Add(webOutline); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.outlines.pdf") }; return(output); }