PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 6:41 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jul 06, 2017 11:12 am 
Offline

Joined: Thu Jul 06, 2017 11:07 am
Posts: 2
Hi, I use your component for building PDP from a set of images and other pdf files.
Unfortunately arose a problem with files Tiff.
Your component perfectly working with multi-page monochrome tiffs.
However, when trying to use a color multipage Tiff, to the PDF is added 1 gray blank page instead of multi-page block.
Question: Is there a solution for color, multi-page TIFF?
Here is the code I'm using.
Code:
                            using (Image MyImage = Image.FromFile(pdfPart.Value))
                            {

                                for (int PageIndex = 0; PageIndex < MyImage.GetFrameCount(FrameDimension.Page); PageIndex++)
                                {
                                    MyImage.SelectActiveFrame(FrameDimension.Page, PageIndex);

                                    var stream = new System.IO.MemoryStream();
                                    MyImage.Save(stream, ImageFormat.Tiff);
                                    stream.Position = 0;
                                    XImage img = XImage.FromStream(stream);
   
                                    var page = new PdfPage();

                                    if (img.PixelWidth > img.PixelHeight)
                                        page.Orientation = PdfSharp.PageOrientation.Landscape;
                                    else
                                        page.Orientation = PdfSharp.PageOrientation.Portrait;
                                    outputDocument.AddPage(page);
                                    using (XGraphics xgr = XGraphics.FromPdfPage(outputDocument.Pages[targetPageIndx]))
                                    {
                                        xgr.DrawImage(img, 0, 0);
                                    }
                                    targetPageIndx++;
                                }
                            }


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 06, 2017 12:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!

Instead of calling "Save" and "FromStream", you can call "DrawImage" directly for your "MyImage" object (provided you use the GDI+ build of PDFsharp).

See also:
viewtopic.php?f=2&t=832

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 09, 2017 9:18 am 
Offline

Joined: Thu Jul 06, 2017 11:07 am
Posts: 2
Thanks for the answer.
I changed the code, but the result has not changed.
Tiff monochrome + multipage is converted into PDF, Tiff colored + multi-page is not converted.
I did a search on the форум topics
Quote:
"The current version of PDFsharp relies on Windows / .NET to read images."

This provided me an answer, since Windows also cannot read these images.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 121 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group