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 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 = "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}"); }