public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "AddAndDrawImage.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfCanvas canvas = pdf.Pages[0].Canvas; PdfImage image = pdf.AddImage("Sample data/ammerland.jpg"); canvas.DrawImage(image, 10, 50); // NOTE: PdfDocument.AddImage(System.Drawing.Image) method is not supported in version for .NET Standard using (Bitmap bitmap = new Bitmap("Sample data/pink.png")) { PdfImage image2 = pdf.AddImage(bitmap); canvas.DrawImage(image2, 400, 50, 100, 150, -45); } pdf.Save(pathToFile); } Process.Start(pathToFile); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "AddRecompressedImages.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfCanvas canvas = pdf.Pages[0].Canvas; PdfImageFrames imageFrames = pdf.OpenImage(@"..\Sample Data\pink.png"); PdfImage originalImage = pdf.AddImage(imageFrames[0]); canvas.DrawImage(originalImage, 10, 10, 0); PdfImageFrames imageFramesToRecompress = pdf.OpenImage(@"..\Sample Data\pink.png"); PdfImageFrame frame = imageFramesToRecompress[0]; frame.OutputCompression = PdfImageCompression.Jpeg; frame.JpegQuality = 50; frame.RecompressAlways = true; PdfImage compressedImage = pdf.AddImage(frame); canvas.DrawImage(compressedImage, 210, 10, 0); pdf.Save(pathToFile); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "ColorMasks.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfCanvas canvas = pdf.Pages[0].Canvas; double scale = pdf.Pages[0].Resolution / 150; canvas.ScaleTransform(scale, scale); canvas.Brush.Color = new PdfRgbColor(0, 255, 0); canvas.DrawRectangle(new PdfRectangle(50, 450, 1150, 150), PdfDrawMode.Fill); PdfImage image = pdf.AddImage(@"..\Sample data\pink.png", new PdfRgbColor(255, 0, 255)); canvas.DrawImage(image, 550, 200); pdf.Save(pathToFile); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "ImageMasks.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfCanvas canvas = pdf.Pages[0].Canvas; canvas.Resolution = 150; canvas.Brush.Color = new PdfRgbColor(0, 255, 0); canvas.DrawRectangle(new RectangleF(50, 450, 1150, 150), PdfDrawMode.Fill); PdfImage image = pdf.AddImage("Sample data/pink.png", "Sample data/pinkMask.tif"); canvas.DrawImage(image, 550, 200); pdf.Save(pathToFile); } Process.Start(pathToFile); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string outputFileName = "SignSignatureFieldUsingCustomStyle.pdf"; using (PdfDocument pdf = new PdfDocument(@"..\Sample Data\SignatureFields.pdf")) { // IMPORTANT: // Replace "keystore.p12" and "password" with your own .p12 or .pfx path and password. // Without the change the sample will not work. PdfSignatureField field = pdf.GetControl("Control") as PdfSignatureField; field.BackgroundColor = new PdfGrayColor(80); PdfSigningOptions options = new PdfSigningOptions("keystore.p12", "password") { DigestAlgorithm = PdfDigestAlgorithm.Sha256, Format = PdfSignatureFormat.Pkcs7Detached, Field = field, Reason = "Testing field styles", Location = "My workplace", ContactInfo = "*****@*****.**" }; PdfSignatureAppearanceOptions appearance = options.Appearance; appearance.IncludeDate = false; appearance.IncludeDistinguishedName = false; appearance.Image = pdf.AddImage(@"..\Sample Data\ammerland.jpg"); appearance.Font = pdf.AddFont(PdfBuiltInFont.Courier); appearance.FontSize = 0; // calculate font size automatically appearance.FontColor = new PdfRgbColor(0, 0, 255); appearance.TextAlignment = PdfSignatureTextAlignment.Right; appearance.NameLabel = "Digital signiert von"; appearance.ReasonLabel = "Grund:"; appearance.LocationLabel = "Ort:"; pdf.SignAndSave(options, outputFileName); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit https://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. using (PdfDocument pdf = new PdfDocument()) { string[] tiffFiles = { @"Sample Data\multipage.tif", @"Sample Data\pinkMask.tif" }; int imagesAdded = 0; foreach (string tiff in tiffFiles) { // open potentially multipage TIFF PdfImageFrames frames = pdf.OpenImage(tiff); foreach (PdfImageFrame frame in frames) { if (imagesAdded != 0) { pdf.AddPage(); } PdfImage image = pdf.AddImage(frame); PdfPage pdfPage = pdf.Pages[pdf.PageCount - 1]; // adjust page size, so image fill occupy whole page pdfPage.Height = image.Height; pdfPage.Width = image.Width; pdfPage.Canvas.DrawImage(image, 0, 0, pdfPage.Width, pdfPage.Height, 0); imagesAdded++; } } pdf.Save("TiffToPdf.pdf"); } Process.Start("TiffToPdf.pdf"); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "AddAndDrawImage.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfCanvas canvas = pdf.Pages[0].Canvas; PdfImage image = pdf.AddImage(@"..\Sample data\ammerland.jpg"); canvas.DrawImage(image, 10, 50); pdf.Save(pathToFile); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "ButtonImage.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfPage page = pdf.Pages[0]; PdfButton button = page.AddButton(10, 50, 100, 100); button.Image = pdf.AddImage(@"..\Sample Data\pink.png"); button.Layout = PdfButtonLayout.ImageOnly; pdf.Save(pathToFile); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "ButtonImage.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfPage page = pdf.Pages[0]; PdfButton button = page.AddButton(10, 50, 100, 100); button.Image = pdf.AddImage(@"Sample Data\\pink.png"); button.Layout = PdfButtonLayout.ImageOnly; pdf.Save(pathToFile); } Process.Start(pathToFile); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "AddSingleImageFrame.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfImageFrames frames = pdf.OpenImage(@"Sample Data\multipage.tif"); PdfImageFrame secondFrame = frames[1]; PdfImage image = pdf.AddImage(secondFrame); pdf.Pages[0].Canvas.DrawImage(image, 10, 10, 0); pdf.Save(pathToFile); } Process.Start(pathToFile); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "AddSingleImageFrame.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfImageFrames frames = pdf.OpenImage(@"..\Sample Data\multipage.tif"); PdfImageFrame secondFrame = frames[1]; PdfImage image = pdf.AddImage(secondFrame); pdf.Pages[0].Canvas.DrawImage(image, 10, 10, 0); pdf.Save(pathToFile); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
private static void CreateApplicantForm(List <ApplicantStudent> applicantStudents) { string pathToFile = ""; using (PdfDocument pdf = new PdfDocument("Sample Data/sonSedat.pdf")) // doldurulabilir boş form pdf'i { List <PdfControl> controls = pdf.GetControls().ToList(); for (int i = 0; i < applicantStudents.Count; i++) { PdfCanvas canvas = pdf.Pages[0].Canvas; using (Bitmap bitmap = applicantStudents[i].Image) { PdfImage image2; if (bitmap is null) { Console.WriteLine(applicantStudents[i].Name + " " + applicantStudents[i].Surname + " Adlı kişinin fotoğrafı bulunamadı, varsayılan resim atanıyor..."); image2 = pdf.AddImage(new Bitmap("Sample Data/user.png")); } else { image2 = pdf.AddImage(bitmap); } canvas.DrawImage(image2, 461, 110, 90, 113, 0); // kişinin fotoğrafının yerleştirileceği koordinat } for (int j = 0; j < controls.Count; j++) { ((PdfTextBox)controls[j]).FontSize = 10; // son.pdf dosyasındaki fillable alanları bulup, excell dosyasından gelen verileri yazdırır. switch (controls[j].Name) { case "basvuruNo": ((PdfTextBox)controls[j]).Text = applicantStudents[i].ApplicationNo.ToString().Substring(0, 8).ToUpper(); break; case "kimlikNo": ((PdfTextBox)controls[j]).Text = applicantStudents[i].IdentityNo.ToString(); break; case "ad": ((PdfTextBox)controls[j]).Text = applicantStudents[i].Name.ToUpper(); break; case "soyad": ((PdfTextBox)controls[j]).Text = applicantStudents[i].Surname.ToUpper(); break; case "sinavTuru": ((PdfTextBox)controls[j]).Text = applicantStudents[i].ExamType.ToUpper(); break; case "sinavTarihi": ((PdfTextBox)controls[j]).Text = applicantStudents[i].ExamDate.ToUpper(); break; case "sinavYeri": ((PdfTextBox)controls[j]).Text = applicantStudents[i].ExamBuilding.ToUpper(); break; case "sinavSaati": ((PdfTextBox)controls[j]).Text = "10:00"; break; case "sinavSalonu": ((PdfTextBox)controls[j]).Text = applicantStudents[i].ExamClass.ToUpper(); break; case "sinavGrup": ((PdfTextBox)controls[j]).Text = applicantStudents[i].ExamDeskNo.ToUpper(); break; } } pathToFile = $"Outputs/{applicantStudents[i].IdentityNo}.pdf"; pdf.ReplaceDuplicateObjects(); pdf.SaveOptions.Compression = PdfCompression.Flate; pdf.SaveOptions.UseObjectStreams = true; pdf.SaveOptions.RemoveUnusedObjects = true; pdf.SaveOptions.OptimizeIndirectObjects = true; pdf.SaveOptions.WriteWithoutFormatting = true; pdf.RemoveStructureInformation(); pdf.Metadata.Basic.Clear(); pdf.Metadata.DublinCore.Clear(); pdf.Metadata.MediaManagement.Clear(); pdf.Metadata.Pdf.Clear(); pdf.Metadata.RightsManagement.Clear(); pdf.Metadata.Custom.Properties.Clear(); foreach (XmpSchema schema in pdf.Metadata.Schemas) { schema.Properties.Clear(); } pdf.Info.Clear(false); unembedFonts(pdf); pdf.RemoveUnusedResources(); pdf.RemovePieceInfo(); pdf.FlattenControls(); Console.WriteLine( $"{i + 1}. {applicantStudents[i].Name} {applicantStudents[i].Surname} adlı kişinin belgesi oluşturuldu."); pdf.Save(pathToFile); } } }
public static void CreateClassroomParticipantsForm(List <Classroom> classrooms) { foreach (var classroom in classrooms) { using (PdfDocument pdf = new PdfDocument("Sample Data/classroomm.pdf")) // doldurulabilir boş form pdf'i { List <PdfControl> controls = pdf.GetControls().ToList(); PdfCanvas canvas = pdf.Pages[0].Canvas; double axisy = 87.5; int examGroup = 0; int k = 1; PdfTextBox classNoTBox = pdf.GetControl("classNo") as PdfTextBox; classNoTBox.FontSize = 20; Debug.Assert(classNoTBox != null); classNoTBox.Text = classroom.Name.ToUpper(); for (int i = 0; i < classroom.ExamDeskCount; i++) { using (Bitmap bitmap = new Bitmap($"Outputs/Photos/{classroom.ApplicantStudents[i].IdentityNo}.jpg")) { PdfImage image2; image2 = pdf.AddImage(bitmap); if (i < 10) { canvas.DrawImage(image2, 32, axisy, 52, 64, 0); axisy += 66.5; if (i == 9) { axisy = 87.5; } } else { canvas.DrawImage(image2, 311, axisy, 46.5, 64.5, 0); axisy += 66.5; } } string cname = String.Empty; for (int j = 0; j < classroom.ExamDeskCount; j++) { cname = $"p{k.ToString()}name"; PdfTextBox nameTextBox = pdf.GetControl(cname) as PdfTextBox; nameTextBox.FontSize = 6; Debug.Assert(nameTextBox != null); nameTextBox.Text = classroom.ApplicantStudents[i].Name.ToUpper(); cname = $"p{k.ToString()}surname"; PdfTextBox surnameTextBox = pdf.GetControl(cname) as PdfTextBox; surnameTextBox.FontSize = 6; Debug.Assert(surnameTextBox != null); surnameTextBox.Text = classroom.ApplicantStudents[i].Surname.ToUpper(); cname = $"p{k.ToString()}id"; PdfTextBox idTextBox = pdf.GetControl(cname) as PdfTextBox; idTextBox.FontSize = 6; Debug.Assert(idTextBox != null); idTextBox.Text = classroom.ApplicantStudents[i].IdentityNo.ToString().ToUpper(); cname = $"p{k.ToString()}classNo"; PdfTextBox classNoTextBox = pdf.GetControl(cname) as PdfTextBox; classNoTextBox.FontSize = 6; Debug.Assert(classNoTextBox != null); classNoTextBox.Text = classroom.Name.ToUpper(); cname = $"p{k.ToString()}deskNo"; PdfTextBox deskNoTextBox = pdf.GetControl(cname) as PdfTextBox; deskNoTextBox.FontSize = 6; Debug.Assert(deskNoTextBox != null); deskNoTextBox.Text = classroom.ApplicantStudents[i].ExamDeskNo.ToString(); if (k < classroom.ExamDeskCount) { k++; break; } } } string pathToFile = $"Outputs/{classroom.Building} {classroom.Name}.pdf"; pdf.ReplaceDuplicateObjects(); pdf.SaveOptions.Compression = PdfCompression.Flate; pdf.SaveOptions.UseObjectStreams = true; pdf.SaveOptions.RemoveUnusedObjects = true; pdf.SaveOptions.OptimizeIndirectObjects = true; pdf.SaveOptions.WriteWithoutFormatting = true; pdf.RemoveStructureInformation(); pdf.Metadata.Basic.Clear(); pdf.Metadata.DublinCore.Clear(); pdf.Metadata.MediaManagement.Clear(); pdf.Metadata.Pdf.Clear(); pdf.Metadata.RightsManagement.Clear(); pdf.Metadata.Custom.Properties.Clear(); foreach (XmpSchema schema in pdf.Metadata.Schemas) { schema.Properties.Clear(); } pdf.Info.Clear(false); unembedFonts(pdf); pdf.RemoveUnusedResources(); pdf.RemovePieceInfo(); pdf.FlattenControls(); pdf.Save(pathToFile); } } }