public static void Run() { // ExStart:EmbedFontWhileDocCreation // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments(); // Instantiate Pdf object by calling its empty constructor Aspose.Pdf.Document doc = new Aspose.Pdf.Document(); // Create a section in the Pdf object Aspose.Pdf.Page page = doc.Pages.Add(); Aspose.Pdf.Text.TextFragment fragment = new Aspose.Pdf.Text.TextFragment(""); Aspose.Pdf.Text.TextSegment segment = new Aspose.Pdf.Text.TextSegment(" This is a sample text using Custom font."); Aspose.Pdf.Text.TextState ts = new Aspose.Pdf.Text.TextState(); ts.Font = FontRepository.FindFont("Arial"); ts.Font.IsEmbedded = true; segment.TextState = ts; fragment.Segments.Add(segment); page.Paragraphs.Add(fragment); dataDir = dataDir + "EmbedFontWhileDocCreation_out_.pdf"; // Save PDF Document doc.Save(dataDir); // ExEnd:EmbedFontWhileDocCreation Console.WriteLine("\nFont embedded successfully in a PDF file.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:EmbedFontWhileDocCreation // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments(); // Instantiate Pdf object by calling its empty constructor Aspose.Pdf.Document doc = new Aspose.Pdf.Document(); // Create a section in the Pdf object Aspose.Pdf.Page page = doc.Pages.Add(); Aspose.Pdf.Text.TextFragment fragment = new Aspose.Pdf.Text.TextFragment(""); Aspose.Pdf.Text.TextSegment segment = new Aspose.Pdf.Text.TextSegment(" This is a sample text using Custom font."); Aspose.Pdf.Text.TextState ts = new Aspose.Pdf.Text.TextState(); ts.Font = FontRepository.FindFont("Arial"); ts.Font.IsEmbedded = true; segment.TextState = ts; fragment.Segments.Add(segment); page.Paragraphs.Add(fragment); dataDir = dataDir + "EmbedFontWhileDocCreation_out.pdf"; // Save PDF Document doc.Save(dataDir); // ExEnd:EmbedFontWhileDocCreation Console.WriteLine("\nFont embedded successfully in a PDF file.\nFile saved at " + dataDir); }
public PDocument(string fileFullName, HDocument hDocument) { /* * //DEBUG * PDocument_debug(fileFullName, hDocument); * return; */ bodyNode = hDocument.BodyNode; pageTextState = PUtil.TextStateUtil.TextState_Default(); PUtil.TextStateUtil.TextState_ModifyFromHStyles((bodyNode as HNodeTag).Styles, pageTextState); pageMargin = new MarginInfo(4, 4, 4, 12); pageBackground = Aspose.Pdf.Color.FromRgb(1.00, 1.00, 1.00); pdfDocument = new Document(); pdfPage = null; pdfTextFragment = null; pdfImage = null; hyperlinkNode = null; pdfNewLine = null; inlineParagraphMargin = null; pdfFormField = null; pdfRadioButtonFields = new Dictionary <string, RadioButtonField>(); updateCurrentPage(); createBody(); pdfDocument.Save(fileFullName); }
private void createTextFragmentByTagType(HTagType tagType) { if (!HUtil.TagUtil.IsBlockTag(tagType)) { pdfTextFragment = null; return; } pdfTextFragment = new TextFragment(); if (tagType == HTagType.div) { pdfTextFragment.Margin = new MarginInfo(0, 0, 0, 0); } else if (tagType == HTagType.p) { pdfTextFragment.Margin = new MarginInfo(0, 12, 0, 12); } else { pdfTextFragment.Margin = new MarginInfo(0, 0, 0, 0); } return; }
public DocsPaVO.documento.FileDocumento CreaRicevuta(DocsPaVO.utente.InfoUtente userInfo, string idDocument, string text) { byte[] content = null; DocsPaVO.documento.FileDocumento doc = new DocsPaVO.documento.FileDocumento(); Document pdf = new Document(); pdf.Pages.Add(); Aspose.Pdf.Text.TextFragment tf = new Aspose.Pdf.Text.TextFragment(text); pdf.Pages[1].Paragraphs.Add(tf); using (MemoryStream stream = new MemoryStream()) { pdf.Save(stream); if (stream != null) { doc.content = stream.ToArray(); } stream.Close(); } return(doc); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Load source PDF form Aspose.Pdf.Facades.Form form1 = new Aspose.Pdf.Facades.Form(dataDir + "RadioButtonField.pdf"); Document PDF_Template_PDF_HTML = new Document(dataDir + "RadioButtonField.pdf"); foreach (var item in form1.FieldNames) { Console.WriteLine(item.ToString()); Dictionary <string, string> radioOptions = form1.GetButtonOptionValues(item); if (item.Contains("radio1")) { Aspose.Pdf.Forms.RadioButtonField field0 = PDF_Template_PDF_HTML.Form[item] as Aspose.Pdf.Forms.RadioButtonField; Aspose.Pdf.Forms.RadioButtonOptionField fieldoption = new Aspose.Pdf.Forms.RadioButtonOptionField(); fieldoption.OptionName = "Yes"; fieldoption.PartialName = "Yesname"; var updatedFragment = new Aspose.Pdf.Text.TextFragment("test123"); updatedFragment.TextState.Font = FontRepository.FindFont("Arial"); updatedFragment.TextState.FontSize = 10; updatedFragment.TextState.LineSpacing = 6.32f; // Create TextParagraph object TextParagraph par = new TextParagraph(); // Set paragraph position par.Position = new Position(field0.Rect.LLX, field0.Rect.LLY + updatedFragment.TextState.FontSize); // Specify word wraping mode par.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords; // Add new TextFragment to paragraph par.AppendLine(updatedFragment); // Add the TextParagraph using TextBuilder TextBuilder textBuilder = new TextBuilder(PDF_Template_PDF_HTML.Pages[1]); textBuilder.AppendParagraph(par); field0.DeleteOption("item1"); } } PDF_Template_PDF_HTML.Save(dataDir + "RadioButtonField_out.pdf"); // ExEnd:1 }
public static void AddNewLineFeed() { try { // ExStart:AddNewLineFeed // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); Aspose.Pdf.Document pdfApplicationDoc = new Aspose.Pdf.Document(); Aspose.Pdf.Page applicationFirstPage = (Aspose.Pdf.Page)pdfApplicationDoc.Pages.Add(); // Initialize new TextFragment with text containing required newline markers Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("Applicant Name: " + Environment.NewLine + " Joe Smoe"); // Set text fragment properties if necessary textFragment.TextState.FontSize = 12; textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red; // Create TextParagraph object TextParagraph par = new TextParagraph(); // Add new TextFragment to paragraph par.AppendLine(textFragment); // Set paragraph position par.Position = new Aspose.Pdf.Text.Position(100, 600); // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(applicationFirstPage); // Add the TextParagraph using TextBuilder textBuilder.AppendParagraph(par); dataDir = dataDir + "AddNewLineFeed_out.pdf"; // Save resulting PDF document. pdfApplicationDoc.Save(dataDir); // ExEnd:AddNewLineFeed Console.WriteLine("\nNew line feed added successfully.\nFile saved at " + dataDir); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void addTextFragmentOnPage(bool needUpdateCurrentPage = true) { if (pdfTextFragment != null) { if (pdfTextFragment.Segments.Count == 0 || (pdfTextFragment.Segments.Count == 1 && pdfTextFragment.Segments[1].Text == String.Empty)) { // not adding textFragment } else { pdfPage.Paragraphs.Add(pdfTextFragment); if (needUpdateCurrentPage) { updateCurrentPage(); } } pdfTextFragment = null; } }
public static void Run() { // ExStart:CreateLocalHyperlink // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_LinksActions(); // Create Document instance Document doc = new Document(); // Add page to pages collection of PDF file Page page = doc.Pages.Add(); // Create Text Fragment instance Aspose.Pdf.Text.TextFragment text = new Aspose.Pdf.Text.TextFragment("link page number test to page 7"); // Create local hyperlink instance Aspose.Pdf.LocalHyperlink link = new Aspose.Pdf.LocalHyperlink(); // Set target page for link instance link.TargetPageNumber = 7; // Set TextFragment hyperlink text.Hyperlink = link; // Add text to paragraphs collection of Page page.Paragraphs.Add(text); // Create new TextFragment instance text = new TextFragment("link page number test to page 1"); // TextFragment should be added over new page text.IsInNewPage = true; // Create another local hyperlink instance link = new LocalHyperlink(); // Set Target page for second hyperlink link.TargetPageNumber = 1; // Set link for second TextFragment text.Hyperlink = link; // Add text to paragraphs collection of page object page.Paragraphs.Add(text); dataDir = dataDir + "CreateLocalHyperlink_out.pdf"; // Save updated document doc.Save(dataDir); // ExEnd:CreateLocalHyperlink Console.WriteLine("\nLocal hyperlink created successfully.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:RenderingReplaceableSymbols // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); Aspose.Pdf.Document pdfApplicationDoc = new Aspose.Pdf.Document(); Aspose.Pdf.Page applicationFirstPage = (Aspose.Pdf.Page)pdfApplicationDoc.Pages.Add(); // Initialize new TextFragment with text containing required newline markers Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("Applicant Name: " + Environment.NewLine + " Joe Smoe"); // Set text fragment properties if necessary textFragment.TextState.FontSize = 12; textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red; // Create TextParagraph object TextParagraph par = new TextParagraph(); // Add new TextFragment to paragraph par.AppendLine(textFragment); // Set paragraph position par.Position = new Aspose.Pdf.Text.Position(100, 600); // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(applicationFirstPage); // Add the TextParagraph using TextBuilder textBuilder.AppendParagraph(par); dataDir = dataDir + "RenderingReplaceableSymbols_out_.pdf"; pdfApplicationDoc.Save(dataDir); // ExEnd:RenderingReplaceableSymbols Console.WriteLine("\nReplaceable symbols render successfully duing pdf creation.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:RenderingReplaceableSymbols // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); Aspose.Pdf.Document pdfApplicationDoc = new Aspose.Pdf.Document(); Aspose.Pdf.Page applicationFirstPage = (Aspose.Pdf.Page)pdfApplicationDoc.Pages.Add(); // Initialize new TextFragment with text containing required newline markers Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("Applicant Name: " + Environment.NewLine + " Joe Smoe"); // Set text fragment properties if necessary textFragment.TextState.FontSize = 12; textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red; // Create TextParagraph object TextParagraph par = new TextParagraph(); // Add new TextFragment to paragraph par.AppendLine(textFragment); // Set paragraph position par.Position = new Aspose.Pdf.Text.Position(100, 600); // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(applicationFirstPage); // Add the TextParagraph using TextBuilder textBuilder.AppendParagraph(par); dataDir = dataDir + "RenderingReplaceableSymbols_out.pdf"; pdfApplicationDoc.Save(dataDir); // ExEnd:RenderingReplaceableSymbols Console.WriteLine("\nReplaceable symbols render successfully duing pdf creation.\nFile saved at " + dataDir); }