And I have a very urgent need to write TIF files and word DOC files to PDFs. Our products already use Infragistics... so I was hoping to elliminate the 3rd party tools we are having problems with and use Infragistics PDF creation.
I see that the Reporting Image component only supports .jpg and .png.
I need to create PDFs from two types of files of either one or both types of external network sourced files (each in a 'section' I guess (I am very new at this)):.DOC Word documents, and/or .TIF files - and the TIFs are possibly multi-paged (all were incoming faxs so would be full page - each on their own PDF page).
I am familiar with System.Drawing.Imaging - paging through a TIF and reading each frame into a MemoryStream object.Is there a simple way to convert a TIF MemoryStream object to a JPG and save it? or can it be directly written to the PDF file?
My guesswork code ideas so far (not even close to debugging) has this for the TIF to PDF -
System.Drawing.Image imageIn = System.Drawing.Image.FromFile(imagePath);Guid objGuid = imageIn.FrameDimensionsList[0];FrameDimension objDimension = new FrameDimension(objGuid);MemoryStream ms = new MemoryStream();Infragistics.Documents.Reports.Graphics.Image img;int pageCount = imageIn.GetFrameCount(FrameDimension.Page);for (int i = 0; i < pageCount; i++){
imageIn.SelectActiveFrame(objDimension, i); img = new Infragistics.Documents.Reports.Graphics.Image(imageIn);// what type will img be??? do we need to hard-define it considering imageIn is a MS System.Drawing.Image component? image = section.AddImage(img); image.Width = new Infragistics.Documents.Reports.Report.FixedWidth(imageIn.Width); image.Margins.Top = 25;}
I'm sure I'm missing a lot of stuff - if this is even remotely close??? Am I close - is there a better way?
Thanks,
Todd
Hi Todd,
The attached code is practically spot-on if you just use Documents Engine, and will save the TIFF contents directly.
If you want to use Reporting to generate the PDF, you can convert the images to JPEG by loading the image like you are doing above, then calling:
imageIn.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);
Héctor
Hi Héctor,
Thanks. I don't know where to find out about how to use the Documents Engine - or is that what I am doing?
The current code I am replacing uses MemoryStream objects - it calls methods like MemoryStream GetPDFfromTIFF(string pathToTiff) from another method that then uses MemoryStream pdf objects to add pages to a main pdf file. I would like to simplify this as much as possible. Are there any samples on how to do this?
I found:
var memoryStream = new MemoryStream(); using (var exporter = ServerExporterFactory.CreateExporter(reportUri)) { exporter.Export(memoryStream, "PDF"); }
but I have no idea where ServerExporterFactory is or how to use it. Is this the 'Document Engine' - or another different way?
the conceptual layout of our current app does this:
I guess my above sample code uses the Reporting methods - you mention Document Engine - where can I find samples / documentation on how to use this? As my concept indicates - we do not view these - they go directly to some output method so maybe Reporting is not the right way.
Can you provide any samples or links to documentation for the Document Engine or which way you think best based on steps 1 and 2 above: DOC/TIF to PDF MemoryStream only?
I have NetAdvantage Ultimate 12.2 downloading 'all' right now. This current project has no Infragistics in it - just 4 3rd party toolsets, some not compatible with SQL Server2008/2012 we are upgrading to - so I'm trying to replace with yours :)... I have been using NetAdvantage 12.1 WinForms in other projects... This project is VS2010 .NET 3.5/4.0 based.
Thank you,Todd
Unfortunately, Documents Engine does not support loading existing PDF or Word documents, and is also unable to merge PDF files.
A close approach to what you are trying to accomplish is to create a Document (instance of Infragistics.Documents.Reports.Report.Report), and then keep adding images for each frame of the TIF files. You can create a section for each image or just a single section for the entire document. Then, for each of the word documents, generate a hyperlink or an attachment in the PDF document. Finally, publish the document to either a file or a stream to save it.
Regards,Héctor
I'm having a little difficulty figuring out how to get this to work in our existing layout:
We have two blocks that loops through all TIF and then all DOC files - creating PDF Memory Stream objects from read TIF and DOC files and adds them to an ArrayList called proccessedComponents
Then we attempt to load the destination PDF file, if it exists already into a MemoryStream pdf object named mergedPDFThen we itterate through the processedComponents Array adding all new pages - preceeded with text and appending each proccessedComponents PDF object to the mergedPDF
So where I am stuck:
So - I am wondering - would it be better to change the MemoryStream objects to report 'sections' - is that even possible without being tied to a single report? I'm trying to not re-write the existing program design, but will if I have to - if it is a better concept. I would still need to know how to import the .doc files into sections then...Thanks for your help,Todd
Todd N said:Thanks. I don't know where to find out about how to use the Documents Engine - or is that what I am doing?
That is what you are doing in the first code snippet. Documents Engine's API is under Infragistics.Documents, whereas Netadvantage Reporting's API is under
Todd N said:but I have no idea where ServerExporterFactory is or how to use it. Is this the 'Document Engine' - or another different way?
ServerExporterFactory is an API exposed by NetAdvantage Reporting, which you can use to generate reports on a server-side scenario. However, you will not be able to attach word documents to the exported PDF files if you use Reporting as there is no way to attach documents to PDF files, with Documents Engine it is possible, though.
Documents Engine documentation
Todd N said:which way you think best based on steps 1 and 2 above: DOC/TIF to PDF MemoryStream only?
It should be like the first code example. I attached a small solution to the post that accomplishes this by using Documents Engine to iterate through the TIFF pages and adds an image in the PDF for each page of the TIFF image.
Let us know if it works.