public virtual void TabsInParagraphTest01() { String outFileName = destinationFolder + "tabsInParagraphTest01.pdf"; String cmpFileName = sourceFolder + "cmp_tabsInParagraphTest01.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)); Document doc = new Document(pdfDoc); float tabWidth = pdfDoc.GetDefaultPageSize().GetWidth() - doc.GetLeftMargin() - doc.GetRightMargin(); Paragraph p = new Paragraph(); p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text." ).Add(new Tab()).Add("Text1").Add("Text2").Add("Text3"); doc.Add(p); p = new Paragraph(); p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text." ).Add(new Tab()).Add("Text1").Add("Tex\nt2").Add("Text3"); doc.Add(p); p = new Paragraph(); p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text." ).Add(new Tab()).Add("Long Long Long Long Long Long Long Text1").Add("Tex\nt2").Add("Text3"); doc.Add(p); PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.CreateJpeg(UrlUtil.ToURL(sourceFolder + "Desert.jpg" ))); iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject, 100); p = new Paragraph(); p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then texts and an image." ).Add(new Tab()).Add("Text1").Add(image).Add("Text3"); doc.Add(p); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
//PDF Brief drucken Button private void Button_Click(object sender, RoutedEventArgs e) { // Abfrage ob man die PDF speichern möchte SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Files(*.pdf)|*.pdf"; saveFileDialog.AddExtension = true; saveFileDialog.DefaultExt = ".pdf"; if (saveFileDialog.ShowDialog() == true) { string path = saveFileDialog.FileName; //writer instanzieren PdfWriter writer = new PdfWriter(path); //pdfdocument erzeugen PdfDocument pdf = new PdfDocument(writer); //Document erzeugen using (Document document = new Document(pdf, PageSize.A4)) { //Einfügen in das document Image logo = new Image(ImageDataFactory.CreateJpeg(new Uri($"{Directory.GetCurrentDirectory()}\\logo.jpg", UriKind.Absolute))); logo.ScaleAbsolute(180f, 50f); logo.SetFixedPosition(400f, 750f); document.Add(logo); document.Add(new Paragraph(TB_vname.Text + " " + TB_nname.Text).SetFixedPosition(45f, 780f, 800f)); document.Add(new Paragraph(TB_strasse.Text + " " + TB_hsnr.Text).SetFixedPosition(45f, 760f, 800f)); document.Add(new Paragraph(TB_plz.Text + " " + TB_ort.Text).SetFixedPosition(45f, 740f, 800)); document.Add(new Paragraph(Betreff.Text).SetFixedPosition(45f, 600f, 800f)); document.Add(new Paragraph(Anrede.Text).SetFixedPosition(90f, 500f, 800f)); Image inhalt = new Image(ImageDataFactory.CreateJpeg(new Uri($"{Directory.GetCurrentDirectory()}\\inhalt.jpg", UriKind.Absolute))); inhalt.ScaleAbsolute(400f, 400f); inhalt.SetFixedPosition(70f, 100f); document.Add(inhalt); } pdf.Close(); //writer schliesen writer.Close(); //öffnen des documentes Process.Start(path); } else { } }
private MimeFile RenderCertificate(CertificateEntity entity) { using MemoryStream ms = new MemoryStream(); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(ms)); Document doc = new Document(pdfDoc, new PageSize(PageSize.LETTER.GetHeight(), PageSize.LETTER.GetWidth())); PageSize ps = pdfDoc.GetDefaultPageSize(); doc.SetMargins(25f, 0f, 25f, 0f); PdfFont times = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD); PdfFont helvetica = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); doc.SetFont(times).SetFontSize(34); doc.ShowTextAligned("King County Search And Rescue Association", ps.GetWidth() / 2, ps.GetHeight() - 100, TextAlignment.CENTER); var imgName = typeof(CertificateStore).Assembly.GetManifestResourceNames().Single(f => f.EndsWith(".kcsara_logo_color.jpg")); using (var stream = typeof(CertificateStore).Assembly.GetManifestResourceStream(imgName)) { var logoData = new byte[stream.Length]; stream.Read(logoData, 0, logoData.Length); doc.Add(new Image(ImageDataFactory.CreateJpeg(logoData), (ps.GetWidth() - 172) / 2, 330, 172)); } doc.SetFont(helvetica).SetFontSize(18); doc.ShowTextAligned("This Certificate of Achievement is to acknowledge that", ps.GetWidth() / 2, 282, TextAlignment.CENTER); doc.SetFont(times).SetFontSize(30); doc.ShowTextAligned(entity.Name, ps.GetWidth() / 2, 230, TextAlignment.CENTER); doc.ShowTextAligned( new Paragraph().Add("has reaffirmed a dedication to serve the public, through continued\nprofessional development, and completion of a written exam for:") .SetFont(helvetica).SetFontSize(18).SetTextAlignment(TextAlignment.CENTER).SetMultipliedLeading(1.3f), ps.GetWidth() / 2, 160, TextAlignment.CENTER); doc.ShowTextAligned(new Paragraph().Add(entity.Title).SetFont(times).SetFontSize(26).SetTextAlignment(TextAlignment.CENTER), ps.GetWidth() / 2, 120, TextAlignment.CENTER); doc.ShowTextAligned(new Paragraph().Add(string.Format("Issued this {0}{1} Day of {2:MMMM, yyyy}", entity.Completed.Day, GetOrdinal(entity.Completed.Day), entity.Completed)).SetFont(helvetica).SetFontSize(15).SetTextAlignment(TextAlignment.CENTER), ps.GetWidth() / 2, 76, TextAlignment.CENTER); Color grey = new DeviceRgb(200, 200, 200); PdfCanvas canvas = new PdfCanvas(pdfDoc.GetFirstPage()); doc.SetFont(helvetica).SetFontSize(7).SetFontColor(grey); doc.ShowTextAligned(string.Format("Submission {0}", entity.RowKey), 75, 28, TextAlignment.LEFT); doc.ShowTextAligned(url, ps.GetWidth() - 75, 28, TextAlignment.RIGHT); doc.Close(); return(new MimeFile { Data = ms.ToArray(), FileName = entity.Title.ToLowerInvariant().Replace(" ", "-") + ".pdf", MimeType = "application/pdf" }); }
public virtual void ImageAlignmentTest01() { String outFileName = destinationFolder + "imageAlignmentTest01.pdf"; String cmpFileName = sourceFolder + "cmp_imageAlignmentTest01.pdf"; PdfWriter writer = new PdfWriter(outFileName); PdfDocument pdfDoc = new PdfDocument(writer); Document doc = new Document(pdfDoc); PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.CreateJpeg(UrlUtil.ToURL(sourceFolder + "Desert.jpg" ))); iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject, 100).SetHorizontalAlignment(HorizontalAlignment .RIGHT); doc.Add(image); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public static void CreatePDF(Card[] cardsData) { Console.Write("Creating PDF... "); var imageDict = GetFiles(cardsData); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(File.Open(pdfPath, FileMode.OpenOrCreate))); var document = new Document(pdfDoc, PageSize.A4); int rowIndex = 0; int columnIndex = 0; int pageIndex = 1; foreach (var card in imageDict) { var imageData = ImageDataFactory.CreateJpeg(card.Key); for (int i = 0; i < card.Value; i++) { var image = new Image(imageData); image.SetWidth(CARD_WIDTH_PX); image.SetHeight(CARD_HEIGHT_PX); image.SetFixedPosition(rowIndex * CARD_WIDTH_PX, PAGE_WIDTH_PX - columnIndex * CARD_HEIGHT_PX); image.SetPageNumber(pageIndex); document.Add(image); rowIndex++; if (rowIndex >= CARD_PER_ROW) { columnIndex++; rowIndex = 0; } if (columnIndex >= CARD_PER_COLUMN) { columnIndex = 0; document.GetPdfDocument().AddNewPage(); pageIndex++; } } } document.Close(); Console.WriteLine($"Done! File saved at {pdfPath}"); }
private void Createpdf() { FileStream output = new FileStream(path + "livro.pdf", FileMode.Create); PdfWriter writer = new PdfWriter(output); PdfDocument pdfdoc = new PdfDocument(writer); Document document = new Document(pdfdoc, PageSize.A3.Rotate()); foreach (Uri ur in images) { Image img = new Image(ImageDataFactory.CreateJpeg(ur)); img.ScaleToFit(PageSize.A3.GetHeight(), PageSize.A3.GetWidth()); document.Add(img); } document.Close(); status.Text = ""; MessageBox.Show("Download Concluido"); }
/// <summary> /// Devuelve una imagen con la marca de agua. /// </summary> public static Image GetMarcaDeAgua() { Image imagen = null; string ruta = App.Global.Configuracion.RutaMarcaAgua; if (File.Exists(ruta)) { string x = Path.GetExtension(ruta).ToLower(); switch (Path.GetExtension(ruta).ToLower()) { case ".jpg": imagen = new Image(ImageDataFactory.CreateJpeg(new Uri(ruta))); break; case ".png": imagen = new Image(ImageDataFactory.CreatePng(new Uri(ruta))); break; } } return(imagen); }
public virtual void ImageTest02() { String outFileName = destinationFolder + "imageTest02.pdf"; String cmpFileName = sourceFolder + "cmp_imageTest02.pdf"; PdfWriter writer = new PdfWriter(outFileName); PdfDocument pdfDoc = new PdfDocument(writer); Document doc = new Document(pdfDoc); PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.CreateJpeg(UrlUtil.ToURL(sourceFolder + "Desert.jpg" ))); iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject, 100); Paragraph p = new Paragraph(); p.Add(new Text("before image")); p.Add(image); p.Add(new Text("after image")); doc.Add(p); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void BlockAlignmentTest02() { String outFileName = destinationFolder + "blockAlignmentTest02.pdf"; String cmpFileName = sourceFolder + "cmp_blockAlignmentTest02.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDocument); Div div = new Div(); PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.CreateJpeg(UrlUtil.ToURL(sourceFolder + "Desert.jpg" ))); iText.Layout.Element.Image image1 = new iText.Layout.Element.Image(xObject, 100).SetHorizontalAlignment(HorizontalAlignment .RIGHT); iText.Layout.Element.Image image2 = new iText.Layout.Element.Image(xObject, 100).SetHorizontalAlignment(HorizontalAlignment .CENTER); iText.Layout.Element.Image image3 = new iText.Layout.Element.Image(xObject, 100).SetHorizontalAlignment(HorizontalAlignment .LEFT); div.Add(image1).Add(image2).Add(image3); document.Add(div); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
private static async Task Main(string[] args) { Console.WriteLine("CMD Signing Docs Demo..."); var amaOptions = LoadFromJsonFile(); var amaCert = LoadAmaCertificate(); var encryptionHelper = new EncryptionHelper(amaCert); var amaService = new AmaSigningService(amaOptions, encryptionHelper); Console.WriteLine("Please introduce your phone number: "); var phoneNumber = Console.ReadLine(); var userCertificatesChain = await amaService.GetUserCertificateChainAsync(phoneNumber !); var pdfToBeSigned = "d:\\code\\ama\\doc1.pdf"; var temporaryPdf = "d:\\code\\ama\\doc1_int.pdf"; var finalPdf = "d:\\code\\ama\\doc1_signed.pdf"; // freetsa -> config information: https://www.freetsa.org/guide/demonstration-digitally-signed-PDF-documents.html var tsaClient = new TSAClientBouncyCastle("https://freetsa.org/tsr"); // crl list for revocation var crlClients = new List <ICrlClient> { new CrlClientOnline(userCertificatesChain.ToArray()) }; // added ocsp client var ocspClient = new OcspClientBouncyCastle(null); var pdfSigner = new PdfSigningManager(userCertificatesChain, crlClients: crlClients, ocspClient: ocspClient, tsaClient: tsaClient); var pathToLogo = "d:\\code\\ama\\logo.jpg"; var logo = ImageDataFactory.CreateJpeg(new Uri(pathToLogo)); var hashInformation = pdfSigner.CreateTemporaryPdfForSigning(new SigningInformation(pdfToBeSigned, temporaryPdf, Reason: "Because yes", Location: "Funchal", Logo: logo)); Console.WriteLine("Please introduce your CMD signing pin: "); var cmdSigningPin = ReadSecretValueFromConsole(); var processId = await amaService.StartDocSigningProcessAsync(hashInformation.HashForSigning, "Doc1.pdf", phoneNumber !, cmdSigningPin !); Console.WriteLine($"{Environment.NewLine}Please introduce the PIN you've received on your phone"); var otpCode = Console.ReadLine(); var signature = await amaService.ConfirmDocSigningAsync(otpCode !, processId); pdfSigner.SignIntermediatePdf(new SignatureInformation(temporaryPdf, finalPdf, signature, hashInformation.NakedHash, null)); Console.WriteLine("Document signed"); Process.Start("cmd.exe ", $"/c {finalPdf}"); }