private bool ConvertTiffToPDF(string imagePath) { try { string[] strArrays = ImageToPDFConverter.SplitTiff(imagePath); for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; PDPage pDPage = new PDPage(); this.pdfFile.addPage(pDPage); PDImageXObject pDImageXObject = PDImageXObject.createFromFile(str, this.pdfFile); PDRectangle pDRectangle = new PDRectangle((float)(pDImageXObject.getWidth() + 40), (float)(pDImageXObject.getHeight() + 40)); pDPage.setMediaBox(pDRectangle); PDPageContentStream pDPageContentStream = new PDPageContentStream(this.pdfFile, pDPage); pDPageContentStream.drawImage(pDImageXObject, 20f, 20f); pDPageContentStream.close(); } } catch (Exception exception1) { Exception exception = exception1; throw new PDFToolkitException(exception.Message, exception); } return(true); }
private bool ConvertOthersToPDF(string imagePath) { try { PDPage pDPage = new PDPage(); string str = "temp.png"; this.pdfFile.addPage(pDPage); if (Path.GetExtension(imagePath).ToLower() == ".bmp") { ImageToPDFConverter.BmpToPng(new Bitmap(Image.FromFile(imagePath)), str); } else if (Path.GetExtension(imagePath).ToLower() == ".png") { str = imagePath; } else { Image.FromFile(imagePath).Save(str, ImageFormat.Png); } PDImageXObject pDImageXObject = PDImageXObject.createFromFile(str, this.pdfFile); PDRectangle pDRectangle = new PDRectangle((float)(pDImageXObject.getWidth() + 40), (float)(pDImageXObject.getHeight() + 40)); pDPage.setMediaBox(pDRectangle); PDPageContentStream pDPageContentStream = new PDPageContentStream(this.pdfFile, pDPage); pDPageContentStream.drawImage(pDImageXObject, 20f, 20f); pDPageContentStream.close(); } catch (Exception exception1) { Exception exception = exception1; throw new PDFToolkitException(exception.Message, exception); } return(true); }
private bool ConvertJPGToPDF(string imagePath) { try { PDPage pDPage = new PDPage(); this.pdfFile.addPage(pDPage); PDImageXObject pDImageXObject = PDImageXObject.createFromFile(imagePath, this.pdfFile); PDRectangle pDRectangle = new PDRectangle((float)(pDImageXObject.getWidth() + 40), (float)(pDImageXObject.getHeight() + 40)); pDPage.setMediaBox(pDRectangle); PDPageContentStream pDPageContentStream = new PDPageContentStream(this.pdfFile, pDPage); pDPageContentStream.drawImage(pDImageXObject, 20f, 20f); pDPageContentStream.close(); } catch (Exception exception1) { Exception exception = exception1; throw new PDFToolkitException(exception.Message, exception); } return(true); }
internal static PDDocument AddTrialStampIfNecessary(PDDocument pdfFile) { if (PDFHelper.AddStamp) { PDImageXObject pDImageXObject = null; foreach (PDPage page in pdfFile.getPages()) { string str = PDFHelper.CreateLogo("Created with a trial copy of Aquaforest PDF Toolkit", page.getRotation()); if (!string.IsNullOrEmpty(str)) { pDImageXObject = PDImageXObject.createFromFile(str, pdfFile); PDPageContentStream pDPageContentStream = new PDPageContentStream(pdfFile, page, PDPageContentStream.AppendMode.APPEND, true); pDPageContentStream.drawImage(pDImageXObject, 100f, page.getMediaBox().getHeight() - 100f); pDPageContentStream.close(); } } pdfFile.getDocumentCatalog().setOpenAction(PDFHelper.GetJavascriptPopup()); } return(pdfFile); }