private void SetDocumentInfo(PdfDocumentInfo documentInfo) { documentInfo .SetCreator("Denis Yerusalimtsev") .SetSubject("Around cheque") .SetTitle("Cheque"); }
private void ManipulatePdf(PdfDocument pdfDocument, bool setTagged) { Document document = new Document(pdfDocument); if (setTagged) { pdfDocument.SetTagged(); } pdfDocument.GetCatalog().SetLang(new PdfString("en-US")); pdfDocument.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo info = pdfDocument.GetDocumentInfo(); info.SetTitle("iText7 PDF/UA test"); PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true); Paragraph p = new Paragraph(); p.SetFont(font); p.Add(new Text("The quick brown ")); iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX)); foxImage.GetAccessibilityProperties().SetAlternateDescription("Fox"); p.Add(foxImage); p.Add(" jumps over the lazy "); iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG)); dogImage.GetAccessibilityProperties().SetAlternateDescription("Dog"); p.Add(dogImage); document.Add(p); document.Close(); }
public override async Task <MetadataResponse> Get(HttpContent content) { try { IDictionary <string, string> metadata = new Dictionary <string, string>(); Stream resultStream = await content.ReadAsStreamAsync(); if (resultStream != null) { PdfDocument doc = new PdfDocument(new PdfReader(resultStream)); PdfDocumentInfo info = doc.GetDocumentInfo(); foreach (string name in metaNames) { string value = info.GetMoreInfo(name); if (!String.IsNullOrEmpty(value)) { metadata[name] = value; } } } return(new MetadataResponse() { Url = resource.Url, StatusCode = HttpStatusCode.OK, Metadata = metadata, ErrorMessage = null }); } catch (Exception e) { return(new MetadataResponse() { Url = resource.Url, StatusCode = HttpStatusCode.BadRequest, Metadata = null, ErrorMessage = e.Message }); } }
public virtual void CreatePdf(String dest) { //Initialize PDFA document with output intent PdfADocument pdf = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent ("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(INTENT, FileMode.Open, FileAccess.Read ))); //Setting some required parameters pdf.SetTagged(); pdf.GetCatalog().SetLang(new PdfString("en-US")); pdf.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo info = pdf.GetDocumentInfo(); info.SetTitle("iText7 PDF/A-1a example"); //Create PdfMerger instance PdfMerger merger = new PdfMerger(pdf); //Add pages from the first document PdfDocument firstSourcePdf = new PdfDocument(new PdfReader(SRC1)); merger.Merge(firstSourcePdf, 1, firstSourcePdf.GetNumberOfPages()); //Add pages from the second pdf document PdfDocument secondSourcePdf = new PdfDocument(new PdfReader(SRC2)); merger.Merge(secondSourcePdf, 1, secondSourcePdf.GetNumberOfPages()); //Close the documents firstSourcePdf.Close(); secondSourcePdf.Close(); pdf.Close(); }
public virtual void CreatePdf(String dest) { PdfDocument pdf = new PdfDocument(new PdfWriter(dest, new WriterProperties().AddXmpMetadata())); Document document = new Document(pdf); //Setting some required parameters pdf.SetTagged(); pdf.GetCatalog().SetLang(new PdfString("en-US")); pdf.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo info = pdf.GetDocumentInfo(); info.SetTitle("iText7 PDF/UA example"); //Fonts need to be embedded PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true); Paragraph p = new Paragraph(); p.SetFont(font); p.Add(new Text("The quick brown ")); iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX)); //PDF/UA: Set alt text foxImage.GetAccessibilityProperties().SetAlternateDescription("Fox"); p.Add(foxImage); p.Add(" jumps over the lazy "); iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG)); //PDF/UA: Set alt text dogImage.GetAccessibilityProperties().SetAlternateDescription("Dog"); p.Add(dogImage); document.Add(p); document.Close(); }
public static void Run() { using (Converter converter = new Converter(Constants.SAMPLE_PDF_WITH_TOC)) { IDocumentInfo info = converter.GetDocumentInfo(); PdfDocumentInfo pdfInfo = (PdfDocumentInfo)info; Console.WriteLine("Author: {0}", pdfInfo.Author); Console.WriteLine("Creation date: {0}", pdfInfo.CreationDate); Console.WriteLine("Title: {0}", pdfInfo.Title); Console.WriteLine("Version: {0}", pdfInfo.Version); Console.WriteLine("Pages count: {0}", pdfInfo.PagesCount); Console.WriteLine("Width: {0}", pdfInfo.Width); Console.WriteLine("Height: {0}", pdfInfo.Height); Console.WriteLine("Is landscaped: {0}", pdfInfo.IsLandscape); Console.WriteLine("Is Password Protected: {0}", pdfInfo.IsPasswordProtected); Console.WriteLine("Table of contents"); Console.WriteLine(new string('=', 40)); foreach (var tocItem in pdfInfo.TableOfContents) { Console.WriteLine($"{tocItem.Title}: {tocItem.Page}"); } } Console.WriteLine("\nDocument info retrieved successfully."); }
private static void AddMetaInformationForDocument(PdfDocument document, string subject, string title) { PdfDocumentInfo info = document.GetDocumentInfo(); info.SetAuthor("Vantage Driver Management"); info.SetKeywords("Vantage Driver Management PDF Reports"); info.SetCreator("Vantage Driver Management App"); info.SetSubject(subject); info.SetTitle(title); }
protected internal virtual void ManipulatePdf() { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST, new WriterProperties().AddXmpMetadata())); PdfDocumentInfo info = pdfDoc.GetDocumentInfo(); info.SetTitle("New title"); info.AddCreationDate(); pdfDoc.Close(); }
public void ReporteVentas1() { FileInfo file = new FileInfo(DEST); file.Directory.Create(); string dest = "c:/temp/reporte_ventas1.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest, new WriterProperties().AddUAXmpMetadata().SetPdfVersion (PdfVersion.PDF_1_7))); Document document = new Document(pdfDoc, PageSize.LETTER.Rotate()); //TAGGED PDF //Make document tagged //pdfDoc.SetTagged(); //PDF/UA //Set document metadata pdfDoc.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); pdfDoc.GetCatalog().SetLang(new PdfString("en-US")); PdfDocumentInfo info = pdfDoc.GetDocumentInfo(); info.SetTitle("Reporte de Ventas de la Semana"); Paragraph p = new Paragraph(); PdfFont font = PdfFontFactory.CreateFont(); p.SetFont(font); p.SetFontSize(26); p.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); p.Add("Reporte de Ventas de la Semana"); document.Add(p); Table tabla = new Table(2); tabla.SetWidth(200); //tabla.SetBorder(Border.NO_BORDER); for (int i = 0; i < 8; i++) { Cell celda = new Cell().Add(new Paragraph("Celda " + i)); //celda.SetBorder(Border.NO_BORDER); tabla.AddCell(celda); } document.Add(tabla); document.Close(); }
private TitleData extractTitle(PdfDocumentInfo info) { string title = info.GetTitle(); if (string.IsNullOrEmpty(title)) { return(null); } TitleData result = _metaDataFactory.CreateNew(MetaDataType.Title) as TitleData; result.Content = title; return(result); }
public virtual void CreatePdf(String dest) { PdfADocument pdf = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_3A, new PdfOutputIntent ("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(INTENT, FileMode.Open, FileAccess.Read ))); Document document = new Document(pdf, PageSize.A4.Rotate()); document.SetMargins(20, 20, 20, 20); //Setting some required parameters pdf.SetTagged(); pdf.GetCatalog().SetLang(new PdfString("en-US")); pdf.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo info = pdf.GetDocumentInfo(); info.SetTitle("iText7 PDF/A-3 example"); //Add attachment PdfDictionary parameters = new PdfDictionary(); parameters.Put(PdfName.ModDate, new PdfDate().GetPdfObject()); PdfFileSpec fileSpec = PdfFileSpec.CreateEmbeddedFileSpec(pdf, File.ReadAllBytes(System.IO.Path.Combine(DATA )), "united_states.csv", "united_states.csv", new PdfName("text/csv"), parameters, PdfName.Data); fileSpec.Put(new PdfName("AFRelationship"), new PdfName("Data")); pdf.AddFileAttachment("united_states.csv", fileSpec); PdfArray array = new PdfArray(); array.Add(fileSpec.GetPdfObject().GetIndirectReference()); pdf.GetCatalog().Put(new PdfName("AF"), array); //Embed fonts PdfFont font = PdfFontFactory.CreateFont(FONT, true); PdfFont bold = PdfFontFactory.CreateFont(BOLD_FONT, true); // Create content Table table = new Table(UnitValue.CreatePercentArray(new float[] { 4, 1, 3, 4, 3, 3, 3, 3, 1 })) .UseAllAvailableWidth(); using (StreamReader sr = File.OpenText(DATA)) { String line = sr.ReadLine(); Process(table, line, bold, true); while ((line = sr.ReadLine()) != null) { Process(table, line, font, false); } } document.Add(table); //Close document document.Close(); }
private TagsData extractTags(PdfDocumentInfo info) { string[] tags = separate(info.GetKeywords()); if (tags.Length == 0) { return(null); } TagsData result = _metaDataFactory.CreateNew(MetaDataType.Tags) as TagsData; foreach (string tag in tags) { result.AddTag(new Tag(Guid.NewGuid(), tag)); } return(result); }
private AuthorData extractAuthors(PdfDocumentInfo info) { string[] authors = separate(info.GetAuthor()); if (authors.Length == 0) { return(null); } AuthorData result = _metaDataFactory.CreateNew(MetaDataType.Author) as AuthorData; foreach (string author in authors) { result.Add(new Author(Guid.NewGuid(), author)); } return(result); }
public virtual void CreatePdf(String dest) { PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); PdfViewerPreferences preferences = new PdfViewerPreferences(); preferences.SetPrintScaling(PdfViewerPreferences.PdfViewerPreferencesConstants.NONE); preferences.SetNumCopies(5); pdf.GetCatalog().SetViewerPreferences(preferences); PdfDocumentInfo info = pdf.GetDocumentInfo(); info.SetTitle("A Strange Case"); Document document = new Document(pdf, PageSize.A4.Rotate()); document.Add(new Paragraph("Mr. Jekyl and Mr. Hyde")); document.Close(); }
public virtual void CreatePdf(String dest) { PdfDocument pdf = new PdfDocument(new PdfWriter(dest, new WriterProperties().AddXmpMetadata().SetPdfVersion (PdfVersion.PDF_1_6))); PdfDocumentInfo info = pdf.GetDocumentInfo(); info.SetTitle("The Strange Case of Dr. Jekyll and Mr. Hyde"); info.SetAuthor("Robert Louis Stevenson"); info.SetSubject("A novel"); info.SetKeywords("Dr. Jekyll, Mr. Hyde"); info.SetCreator("A simple tutorial example"); Document document = new Document(pdf); document.Add(new Paragraph("Mr. Jekyl and Mr. Hyde")); document.Close(); }
/// <summary> /// Obsługa zapisywania plików wynikowych /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonSave_Click(object sender, EventArgs e) { bool nullPrefix = Global.ScanFiles.Values.Any(o => string.IsNullOrEmpty(o.Prefix)); // czy wszystkie skany zostały zindeksowane if (nullPrefix) { MessageBox.Show(@"Nie wszystkie skany zostały zindeksowane!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string outputDirectory = Path.Combine(Global.LastDirectory, textBoxOperat.Text); // folder wyjściowy na podstawie nazwy wpisanej w polu operat i katalogu ze skanami Directory.CreateDirectory(outputDirectory); // utwórz folder wynikowy List <ScanFile> scanFilesWithoutSkip = Global.ScanFiles.Values.Where(skan => skan.Prefix != "skip").ToList(); for (int i = 0; i < scanFilesWithoutSkip.Count; i++) { IRandomAccessSource byteSource = new RandomAccessSourceFactory().CreateSource(scanFilesWithoutSkip[i].PdfFile); PdfReader pdfReader = new PdfReader(byteSource, new ReaderProperties()); MemoryStream memoryStreamOutput = new MemoryStream(); PdfWriter pdfWriter = new PdfWriter(memoryStreamOutput); PdfDocument pdfDoc = new PdfDocument(pdfReader, pdfWriter); PdfDocumentInfo info = pdfDoc.GetDocumentInfo(); info.SetCreator("GISNET ScanHelper"); pdfDoc.Close(); string fileName = textBoxOperat.Text + "_" + (i + 1) + "-" + scanFilesWithoutSkip[i].Prefix + "-" + scanFilesWithoutSkip[i].TypeCounter.ToString().PadLeft(3, '0') + Path.GetExtension(scanFilesWithoutSkip[i].FileName); File.WriteAllBytes(Path.Combine(outputDirectory, fileName), memoryStreamOutput.ToArray()); } MessageBox.Show("Pliki zapisano!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
public void ManipulatePdf(string src, string dest) { WriterProperties writerProperties = new WriterProperties(); writerProperties.AddXmpMetadata(); PdfWriter pdfWriter = new PdfWriter(dest, writerProperties); PdfDocument pdfDoc = new PdfDocument(pdfWriter); pdfDoc.GetCatalog().SetLang(new PdfString("en-US")); pdfDoc.SetTagged(); pdfDoc.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo pdfMetaData = pdfDoc.GetDocumentInfo(); pdfMetaData.SetAuthor("Samuel Huylebroeck"); pdfMetaData.AddCreationDate(); pdfMetaData.GetProducer(); pdfMetaData.SetCreator("iText Software"); pdfMetaData.SetKeywords("example, accessibility"); pdfMetaData.SetSubject("PDF accessibility"); // Title is derived from html // pdf conversion ConverterProperties props = new ConverterProperties(); FontProvider fontProvider = new FontProvider(); fontProvider.AddStandardPdfFonts(); fontProvider.AddDirectory(SRC); // The noto-nashk font file (.ttf extension) is placed in the resources props.SetFontProvider(fontProvider); // Base URI is required to resolve the path to source files props.SetBaseUri(SRC); // Setup custom tagworker factory for better tagging of headers DefaultTagWorkerFactory tagWorkerFactory = new AccessibilityTagWorkerFactory(); props.SetTagWorkerFactory(tagWorkerFactory); HtmlConverter.ConvertToPdf(new FileStream(src, FileMode.Open), pdfDoc, props); pdfDoc.Close(); }
/* (non-Javadoc) * @see com.itextpdf.html2pdf.attach.ITagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext) */ public virtual void ProcessEnd(IElementNode element, ProcessorContext context) { // Note that charset and http-equiv attributes are processed on DataUtil#parseByteData(ByteBuffer, String, String, Parser) level. String name = element.GetAttribute(AttributeConstants.NAME); if (null != name) { name = name.ToLowerInvariant(); String content = element.GetAttribute(AttributeConstants.CONTENT); // although iText do not visit head during processing html to elements // meta tag can by accident be presented in body section and that shouldn't cause NPE if (null != content && null != context.GetPdfDocument()) { PdfDocumentInfo info = context.GetPdfDocument().GetDocumentInfo(); if (AttributeConstants.AUTHOR.Equals(name)) { info.SetAuthor(content); } else { if (AttributeConstants.APPLICATION_NAME.Equals(name)) { info.SetCreator(content); } else { if (AttributeConstants.KEYWORDS.Equals(name)) { info.SetKeywords(content); } else { if (AttributeConstants.DESCRIPTION.Equals(name)) { info.SetSubject(content); } else { info.SetMoreInfo(name, content); } } } } } } }
//Get PDF document basic informations. private void btnInfo_Click(object sender, RoutedEventArgs e) { if (this.pdfDocumentViewer1.IsDocumentLoaded) { string info = ""; info += "File name: " + this.pdfDocumentViewer1.FileName + "\n"; PdfDocumentInfo docInfo = this.pdfDocumentViewer1.GetDocumentInfomation(); info += "Author: " + docInfo.Author + "\n"; info += "Creator: " + docInfo.Creator + "\n"; info += "Producer: " + docInfo.Producer + "\n"; info += "Title: " + docInfo.Title + "\n"; info += "Subject: " + docInfo.Subject + "\n"; info += "Keywords: " + docInfo.Keywords + "\n"; info += "Creation date: " + docInfo.CreationDate.ToString() + "\n"; info += "Modifaction date: " + docInfo.ModificationDate.ToString() + "\n"; MessageBox.Show(info, "Document information", MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// creates pdf /// </summary> /// <param name="dest"></param> private void CreatePdf(string dest) { //CountryResponse country = Countries[]; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest, new WriterProperties().AddUAXmpMetadata().SetPdfVersion (PdfVersion.PDF_1_7))); Document document = new Document(pdfDoc, PageSize.A4.Rotate()); pdfDoc.SetTagged(); pdfDoc.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); pdfDoc.GetCatalog().SetLang(new PdfString("en-US")); PdfDocumentInfo info = pdfDoc.GetDocumentInfo(); info.SetTitle($"'s Details"); Paragraph p = new Paragraph(); p.Add($"'s Details").SetFontSize(30); document.Add(p); p = new Paragraph("\n\n\n\n").SetFontSize(20); document.Add(p); List list = new List().SetFontSize(20); list.Add(new ListItem($"Capital: ")); list.Add(new ListItem($"Region: ")); list.Add(new ListItem($"Subregion: ")); list.Add(new ListItem($"Population: ")); list.Add(new ListItem($"Area: ")); list.Add(new ListItem($"NativeName: ")); list.Add(new ListItem($"Cioc: ")); list.Add(new ListItem($"NumericCode: ")); document.Add(list); document.Close(); }
/// <summary> /// Creates a new PDF document using provided properties, adds images with /// recognized text. /// </summary> /// <param name="pdfWriter"> /// the /// <see cref="iText.Kernel.Pdf.PdfWriter"/> /// object /// to write final PDF document to /// </param> /// <param name="pdfOutputIntent"> /// /// <see cref="iText.Kernel.Pdf.PdfOutputIntent"/> /// for PDF/A-3u document /// </param> /// <param name="imagesTextData"> /// map that contains input image files as keys, /// and as value: map pageNumber -> text for the page /// </param> /// <returns> /// result /// <see cref="iText.Kernel.Pdf.PdfDocument"/> /// object /// </returns> private PdfDocument CreatePdfDocument(PdfWriter pdfWriter, PdfOutputIntent pdfOutputIntent, IDictionary <FileInfo , IDictionary <int, IList <TextInfo> > > imagesTextData) { PdfDocument pdfDocument; bool createPdfA3u = pdfOutputIntent != null; if (createPdfA3u) { pdfDocument = new PdfADocument(pdfWriter, PdfAConformanceLevel.PDF_A_3U, pdfOutputIntent, new DocumentProperties ().SetEventCountingMetaInfo(new PdfOcrMetaInfo())); } else { pdfDocument = new PdfDocument(pdfWriter, new DocumentProperties().SetEventCountingMetaInfo(new PdfOcrMetaInfo ())); } // pdfLang should be set in PDF/A mode bool hasPdfLangProperty = ocrPdfCreatorProperties.GetPdfLang() != null && !ocrPdfCreatorProperties.GetPdfLang ().Equals(""); if (createPdfA3u && !hasPdfLangProperty) { LOGGER.Error(MessageFormatUtil.Format(OcrException.CANNOT_CREATE_PDF_DOCUMENT, PdfOcrLogMessageConstant.PDF_LANGUAGE_PROPERTY_IS_NOT_SET )); throw new OcrException(OcrException.CANNOT_CREATE_PDF_DOCUMENT).SetMessageParams(PdfOcrLogMessageConstant. PDF_LANGUAGE_PROPERTY_IS_NOT_SET); } // add metadata if (hasPdfLangProperty) { pdfDocument.GetCatalog().SetLang(new PdfString(ocrPdfCreatorProperties.GetPdfLang())); } // set title if it is not empty if (ocrPdfCreatorProperties.GetTitle() != null) { pdfDocument.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo info = pdfDocument.GetDocumentInfo(); info.SetTitle(ocrPdfCreatorProperties.GetTitle()); } // reset passed font provider ocrPdfCreatorProperties.GetFontProvider().Reset(); AddDataToPdfDocument(imagesTextData, pdfDocument, createPdfA3u); return(pdfDocument); }
protected override void WriteToFile() { using (var pdfStream = File.Open(OutputFileLocation, FileMode.Create)) { var pdfFormatProvider = new PdfFormatProvider(); var pdfExportSettings = new PdfExportSettings(); pdfExportSettings.ImagesCompressionMode = PdfImagesCompressionMode.Automatic; pdfExportSettings.ImagesDeflaterCompressionLevel = -1; pdfExportSettings.ContentsCompressionMode = PdfContentsCompressionMode.Automatic; var pdfDocInfo = new PdfDocumentInfo(); pdfDocInfo.Title = this.RootMap.Name; pdfDocInfo.Subject = this.RootMap.Name; pdfDocInfo.Producer = "Glyma Export"; pdfExportSettings.DocumentInfo = pdfDocInfo; pdfFormatProvider.ExportSettings = pdfExportSettings; pdfFormatProvider.Export(Document, pdfStream); } }
/**************************************************************************/ private void LoadMetadata() { this.Metadata.Add("title", ""); this.Metadata.Add("author", ""); this.Metadata.Add("description", ""); this.Metadata.Add("keywords", ""); if (this.Pdf != null) { PdfDocumentInfo pdfInfo = this.Pdf.GetDocumentInfo(); this.Metadata["title"] = pdfInfo.GetTitle(); this.Metadata["author"] = pdfInfo.GetAuthor(); this.Metadata["description"] = pdfInfo.GetSubject(); this.Metadata["keywords"] = pdfInfo.GetKeywords(); } return; }
protected internal virtual void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); PdfDocumentInfo info = pdfDoc.GetDocumentInfo(); IDictionary <String, String> newInfo = new Dictionary <String, String>(); newInfo.Add("Special Character: \u00e4", "\u00e4"); StringBuilder buf = new StringBuilder(); buf.Append((char)0xc3); buf.Append((char)0xa4); newInfo.Add(buf.ToString(), "\u00e4"); info.SetMoreInfo(newInfo); pdfDoc.Close(); }
private static string AddPage(string src, string sourceName, string documentLink, string documentName, string hash) { string dest = System.IO.Path.GetTempFileName(); string temp = System.IO.Path.GetTempFileName(); if (!string.IsNullOrEmpty(sourceName)) { sourceName = Uri.UnescapeDataString(sourceName); } if (!string.IsNullOrEmpty(documentName)) { documentName = Uri.UnescapeDataString(documentName); } PdfDocument pdfSignaturesPage = new PdfDocument(new PdfWriter(temp)); Document docSignatures = new Document(pdfSignaturesPage); docSignatures.Add(new Paragraph("PROTOCOLO DE ASSINATURA(S)").SetFontSize(10).SetBold().SetUnderline()); docSignatures.Add(new Paragraph("O documento acima foi proposto para assinatura digital na plataforma " + sourceName + ".").SetFontSize(10).SetMargin(0)); docSignatures.Add(new Paragraph("Para verificar as assinaturas clique no link: " + documentLink).SetFontSize(10).SetMargin(0)); docSignatures.Add(new Paragraph("Código do documento: " + documentName).SetFontSize(10).SetMargin(0)); docSignatures.Add(new Paragraph("Hash do documento").SetFontSize(10).SetMargin(0)); docSignatures.Add(new Paragraph(hash).SetFontSize(10).SetMargin(0)); docSignatures.Add(new Paragraph("O(s) assinante(s) do documento é(são):").SetFontSize(10).SetMarginLeft(0).SetMarginTop(5)); docSignatures.Close(); pdfSignaturesPage.Close(); PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest)); PdfDocumentInfo info = pdfDoc.GetDocumentInfo(); info.SetTitle(documentName); pdfSignaturesPage = new PdfDocument(new PdfReader(temp)); pdfSignaturesPage.CopyPagesTo(1, 1, pdfDoc); pdfSignaturesPage.Close(); pdfDoc.Close(); return(dest); }
public virtual void CreatePdf(String dest) { PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); PdfViewerPreferences preferences = new PdfViewerPreferences(); preferences.SetFitWindow(true); preferences.SetHideMenubar(true); preferences.SetHideToolbar(true); preferences.SetHideWindowUI(true); preferences.SetCenterWindow(true); preferences.SetDisplayDocTitle(true); pdf.GetCatalog().SetViewerPreferences(preferences); PdfDocumentInfo info = pdf.GetDocumentInfo(); info.SetTitle("A Strange Case"); Document document = new Document(pdf, PageSize.A4.Rotate()); document.Add(new Paragraph("Mr. Jekyl and Mr. Hyde")); document.Close(); }
/// <summary> /// Start new pdf, create try create enviroment and objects /// </summary> /// <param name="pDirTarget">Directory where copy pdf at the end process</param> /// <param name="pFileNameSort">Short filenae of pdf like helloworld.pdf</param> /// <param name="pDocMetaTitle">Short filenae of pdf like helloworld.pdf</param> /// <param name="pDocMetaAuthor">Autor of file</param> /// <param name="pDocMetaCreator">Cretor of file</param> /// <param name="pDocMetaKeyWords">Separeted coma values</param> /// <param name="pDocMetaSubject">Litle description</param> public bool fnc_00_Start(String pDirTarget, String pFileNameSort, String pDocMetaTitle, String pDocMetaAuthor, String pDocMetaCreator, String pDocMetaKeyWords, String pDocMetaSubject) { fncToolClearLastError(); m_DirTarget = pDirTarget; m_FileNameSort = pFileNameSort; m_DocMetaTitle = pDocMetaTitle; m_DocMetaAuthor = pDocMetaAuthor; m_DocMetaCreator = pDocMetaCreator; m_DocMetaKeyWords = pDocMetaKeyWords; m_DocMetaSubject = pDocMetaSubject; m_FileNameTemp = fncToolPathCombine(m_DirTemp, pFileNameSort); m_FileNameTarget = fncToolPathCombine(pDirTarget, pFileNameSort); // creation global objects, and directories ... and set metas try { System.IO.Directory.CreateDirectory(m_DirTemp); System.IO.Directory.CreateDirectory(pDirTarget); if (System.IO.File.Exists(m_FileNameTemp)) { System.IO.File.Delete(m_FileNameTemp); } m_PdfWriter = new PdfWriter(m_FileNameTemp); m_PdfDoc = new PdfDocument(m_PdfWriter); m_info = m_PdfDoc.GetDocumentInfo(); m_info.SetTitle(m_DocMetaTitle); m_info.SetAuthor(pDocMetaAuthor); m_info.SetCreator(pDocMetaCreator); m_info.SetKeywords(pDocMetaKeyWords); m_info.SetSubject(pDocMetaSubject); m_Document = new Document(m_PdfDoc, PageSize.A4); } catch (Exception xcpt) { m_IsError = true; m_ErrorMsg = xcpt.Message; } return(!m_IsError); }
private void ManipulatePdf(String dest) { PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H); Stream fileStream = new FileStream("../../../resources/data/sRGB_CS_profile.icm", FileMode.Open, FileAccess.Read); PdfADocument pdfDoc = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", "", null, "sRGB IEC61966-2.1", fileStream)); pdfDoc.GetCatalog().SetLang(new PdfString("nl-nl")); pdfDoc.SetTagged(); Document doc = new Document(pdfDoc); doc.SetMargins(MARGIN_OF_ONE_CM, MARGIN_OF_ONE_CM, MARGIN_OF_ONE_CM, MARGIN_OF_ONE_CM); PdfDocumentInfo info = pdfDoc.GetDocumentInfo(); info .SetTitle("title") .SetAuthor("Author") .SetSubject("Subject") .SetCreator("Creator") .SetKeywords("Metadata, iText, PDF") .SetCreator("My program using iText") .AddCreationDate(); Paragraph element = new Paragraph("Hello World").SetFont(font).SetFontSize(10); doc.Add(element); Image logoImage = new Image(ImageDataFactory.Create(LOGO)); logoImage.GetAccessibilityProperties().SetAlternateDescription("Logo"); doc.Add(logoImage); doc.Close(); }
private void button1_Click(object sender, System.EventArgs e) { _c1pdf.Clear(); RectangleF rc = _c1pdf.PageRectangle; rc.Inflate(-72, -72); _c1pdf.DrawString(textBox1.Text, textBox1.Font, Brushes.Black, rc); string infoString = "single char: 不明だった炭素の"; PdfDocumentInfo info = _c1pdf.DocumentInfo; info.Author = infoString; info.Creator = infoString; info.Keywords = infoString; info.Producer = infoString; info.Subject = infoString; info.Title = infoString; // save and show pdf document string fileName = string.Format(@"{0}\{1}.pdf", Path.GetDirectoryName(Application.ExecutablePath), _cmbLanguage.Text); _c1pdf.Save(fileName); Process.Start(fileName); }
/// <summary> /// Sets the title. /// </summary> /// <param name="pdfFilePath">The PDF file path.</param> /// <param name="title">The title.</param> internal static void SetTitle(string pdfFilePath, string title) { if (string.IsNullOrEmpty(title)) { return; } string tempFilePath = Path.GetTempFileName(); using (PdfReader pdfReader = new PdfReader(pdfFilePath)) { using (PdfWriter pdfWriter = new PdfWriter(tempFilePath)) { using (iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(pdfReader, pdfWriter)) { PdfDocumentInfo pdfDocumentInfo = pdfDocument.GetDocumentInfo(); pdfDocumentInfo.SetTitle(title); } } } File.Delete(pdfFilePath); File.Move(tempFilePath, pdfFilePath); }