private void button2_Click(object sender, EventArgs e) { string printername = ""; PrintDialog pd = new PrintDialog(); if (pd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { printername = pd.PrinterSettings.PrinterName; try { HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(); htmlToPdfConverter.LicenseKey = "sjwvPS4uPSskPSgzLT0uLDMsLzMkJCQk"; htmlToPdfConverter.HtmlViewerWidth = 850; htmlToPdfConverter.PdfDocumentOptions.AvoidImageBreak = true; byte[] outPdfBuffer = htmlToPdfConverter.ConvertHtml(winFormHtmlEditor1.DocumentHtml, ""); InputPdf inputPdf = new InputPdf(outPdfBuffer); //PrinterSettings settings = new PrinterSettings(); PrintJob printJob = new PrintJob(printername, inputPdf); printJob.DocumentName = ReportCombo.Text.Replace(" ", "_").Replace("/", ""); PrintJob.AddLicense("FPM20NXDLB2DHPnggbYuVwkquSU3u2ffoA/Pgph4rjG5wiNCxO8yEfbLf2j90rZw1J3VJQF2tsniVvl5CxYka6SmZX4ak6keSsOg"); printJob.PrintOptions.Scaling = new AutoPageScaling(); printJob.Print(); } catch (Exception ee) { Logger.Instance.WriteToLog(ee.ToString()); } } }
public static void Run() { // Get the source PDF which has the attachments as byte data byte[] pdfArray = System.IO.File.ReadAllBytes(Util.GetPath("Resources/PdfWithAttachments.pdf")); // Create an InputPdf object using the PDF byte data InputPdf inputPdf = new InputPdf(pdfArray); // Loop through the attachments for (int i = 0; i < inputPdf.Attachments.Length; i++) { if (inputPdf.Attachments[i] != null) { InputPdf attachedPdf = inputPdf.Attachments[i].TryGetPdf(); if (attachedPdf != null) { // Create a print job with the document to be printed to the default printer PrintJob printJob = new PrintJob(Printer.Default, attachedPdf); // Print the print job printJob.Print(); } } } }
public static void RunActualPaperScaling() { InputPdf pdf = new InputPdf(Util.GetPath("Resources/DocumentA.pdf")); // Create a print job with the document to be printed to the default printer PrintJob printJob = new PrintJob(Printer.Default); printJob.Pages.Add(pdf); printJob.PrintOptions.Scaling = PageScaling.ActualSize; //Print the job printJob.Print(); }
public static void RunPageEdgeScaling() { InputPdf pdf = new InputPdf(Util.GetPath("Resources/DocumentA.pdf")); // Create a print job with the document to be printed to the default printer PrintJob printJob = new PrintJob(Printer.Default); printJob.Pages.Add(pdf); // Set AutoPageScaling printJob.PrintOptions.Scaling = new AutoPageScaling(ScaleTo.PageEdges); //Print the job printJob.Print(); }
internal static void Run() { // Get a byte array containing the source PDF byte[] pdfArray = System.IO.File.ReadAllBytes(Util.GetResourcePath("PortFolio.pdf")); // Create an input PDF from the byte array InputPdf inputPdf = new InputPdf(pdfArray); // Get an array of the attachments in the input PDF Attachment[] files = inputPdf.Attachments; // Gets the first attachment as a PDF if it is a PDF file InputPdf inputPdfFile = files[0].TryGetPdf(); // Create a PdfRasterizer object PdfRasterizer rasterizer = new PdfRasterizer(inputPdfFile); // Save the image rasterizer.Draw("PdfPortfolio.png", ImageFormat.Png, ImageSize.Dpi96); }
public Task <Stream> GenerateCover(Stream file) { if (file is null) { throw new ArgumentNullException(nameof(file)); } Stream imageStream = null; var task = Task.Factory.StartNew(() => { InputPdf input = new InputPdf(file); PdfRasterizer pdf = new PdfRasterizer(input); byte[] image = pdf.Pages[0].Draw(ImageFormat.Jpeg, ImageSize.Dpi72); imageStream = new MemoryStream(image); }); return(Task.WhenAll(task).ContinueWith(t => { return imageStream; })); }
public static void Print(string html_string, string printername) { try { string body = ""; HtmlToPdfConverter converter = GetInitializedHtmlConverter(html_string, out body); byte[] outPdfBuffer = converter.ConvertHtml(body, ""); InputPdf inputPdf = new InputPdf(outPdfBuffer); //PrinterSettings settings = new PrinterSettings(); PrintJob printJob = new PrintJob(printername, inputPdf); PrintJob.AddLicense("FPM20NXDLB2DHPnggbYuVwkquSU3u2ffoA/Pgph4rjG5wiNCxO8yEfbLf2j90rZw1J3VJQF2tsniVvl5CxYka6SmZX4ak6keSsOg"); printJob.PrintOptions.Scaling = new AutoPageScaling(); printJob.Print(); } catch (Exception ee) { Logger.Instance.WriteToLog(ee.ToString()); } }
private void button2_Click(object sender, EventArgs e) { string printername = ""; PrintDialog pd = new PrintDialog(); if (pd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { printername = pd.PrinterSettings.PrinterName; try { HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(); htmlToPdfConverter.LicenseKey = "sjwvPS4uPSskPSgzLT0uLDMsLzMkJCQk"; htmlToPdfConverter.HtmlViewerWidth = 850; htmlToPdfConverter.PdfDocumentOptions.AvoidImageBreak = true; byte[] outPdfBuffer = htmlToPdfConverter.ConvertHtml(winFormHtmlEditor1.DocumentHtml, ""); InputPdf inputPdf = new InputPdf(outPdfBuffer); //PrinterSettings settings = new PrinterSettings(); PrintJob printJob = new PrintJob(printername, inputPdf); printJob.DocumentName = ReportCombo.Text.Replace(" ", "_").Replace("/",""); PrintJob.AddLicense("FPM20NXDLB2DHPnggbYuVwkquSU3u2ffoA/Pgph4rjG5wiNCxO8yEfbLf2j90rZw1J3VJQF2tsniVvl5CxYka6SmZX4ak6keSsOg"); printJob.PrintOptions.Scaling = new AutoPageScaling(); printJob.Print(); } catch (Exception ee) { Logger.Instance.WriteToLog(ee.ToString()); } } }