PdfWriter.getInstance(document,System.out) įileOutputStream("C:/shib/PHP SQL UNIX INTERVIEW HELPER.pdf")) Public static void main(String arg)throws Exceptionĭocument document = new Document(PageSize.A4, 36, 72, 108, 180) I tried with the below code, but it is converting the text part only and rest in some ambiguous format. Please help me with a proper sample code or tutorial to convert any word and html document (. ) to. pdf format, but have not been successful. It's worth noting that the main method returns a byte array, which I needed in my specific scenario because I had to put the resulting PDF file into a DB blob column: you can modify the return value to get the MemoryStream, force an IO write somewhere in your hard-drive or anything else that might suit you better.I am trying to convert. but be wary of the fact that it could break on other machines! You will notice a wide amount of nested (and non-nested) using blocks, which often happens when working with GDI+ image types (most of them implement the IDisposable interface, hence we have to manually dispose them) and also some Bitmap-into-Bitmap transformations which could seem rather odd at first: these are nothing less than attempts to properly deal with GDI+, which often throws the generic GDI+ error otherwise (in some evironments): if you are confident you can securely shrink the code feel free to do that. The source code of the MergeIntoPDF method is pretty much self-explanatory. skip it (or throw an exception if you prefer) Pdf.AddPage(pdf.GetImportedPage(reader, i + 1)) Using (var reader = new PdfReader(info.Data))įor (int i = 0 i < reader.NumberOfPages i++) TiffImage.Save(tempImg, ImageFormat.Tiff) Using (MemoryStream tempImg = new MemoryStream()) TiffImage.SelectActiveFrame(currentFrame, index) Int noOfPages = tiffImage.GetFrameCount(dimension) įoreach (ImageCodecInfo i in ImageCodecInfo.GetImageEncoders())įoreach (Guid guid in tiffImage.FrameDimensionsList)įor (int index = 0 index < noOfPages index++)įrameDimension currentFrame = new FrameDimension(guid) Gets the total number of frames in the. Guid objGuid = tiffImage.FrameDimensionsList įrameDimension dimension = new FrameDimension(objGuid) get the globally unique identifier (GUID) Using (var imageStream = new MemoryStream(info.Data)) Get the frame dimension list from the image of the file Var page = pdf.GetImportedPage(imageDocumentReader, 1) Using (PdfReader imageDocumentReader = new PdfReader(imageMS.ToArray())) Throw new Exception("Unable to add image to page!") Using (imageDocumentWriter = PdfWriter.GetInstance(imageDocument, imageMS)) Using (PdfCopy pdf = new PdfCopy(doc, ms))įoreach (ByteArrayInfo info in infoArray) PdfWriter wri = PdfWriter.GetInstance(doc, ms) patch to fix the "PdfReader not opened with owner password" error. If (infoArray.Length = 1 & ('.').ToLower() = "pdf") return infoArray.Data If we do have a single PDF file, return it without doing anything Public static byte MergeIntoPDF(params ByteArrayInfo infoArray) / Supported Formats: bmp, gif, jpg, jpeg, png, tif, tiff, pdf (including multi-page tiff and pdf files) / Merge one or more image or document files into a single PDF
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |