View previous topic :: View next topic |
Author |
Message |
neilw
Joined: 31 Mar 2009 Posts: 3
|
Posted: Tue Mar 31, 2009 12:32 pm Post subject: bitonal tiff images bug/adding from System Bitmap |
|
|
Hello,
I've just started using pdfSharp and wondered if anyone can answer these two simple questions.
1. Is there a way to add an image from anything other than a file? I already have the Bitmap in memory so it seems a bit daft to save it then add it to the pdf. I saw Add() method but that takes a pdfsharp type of image, whereas I have a System.Drawing.Image
2. If I add an image to my pdf (using AddImage) and my image is a png or a 24bpp tiff, all is well. If I add a bitonal tiff (I've tried 200dpi and 96dpi) all I get is the top corner of the image. I have to set the page height/width to a massive number in order to show it. I tried using:
section.PageSetup.PageHeight = Unit.FromPoint(i.Height*72/i.VerticalResolution);
But the same thing happens. It is only with bitonal TIFF that fails.
Thanks. |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Tue Mar 31, 2009 1:21 pm Post subject: |
|
|
Hi!
Re 1:
With PDFsharp you can use System.Drawing.Image; with MigraDoc you need a file-based image.
Re 2:
Should be simple with PDFsharp (see PageSizes sample).
Should also work with MigraDoc (you need a new section for every new page).
Depending on your images it may be more convenient for the user to have a constant page size and to re-size the images to fit the page (maintaining the aspect ratio so you'll get some padding).
If only certain TIFF files fail there may be something special about them - or there may be a bug in MigraDoc/PDFsharp with respect to those special images. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
neilw
Joined: 31 Mar 2009 Posts: 3
|
Posted: Tue Mar 31, 2009 1:25 pm Post subject: |
|
|
Thanks.
I used migradoc because it said pdfsharp was the low level library and all I wanted was some simple stuff. So I'll check it out to see how easy it is.
As for the TIFF, I've found the problem. I was using a 1bpp conversion library I found at CodeProject but there's a bug in that they don't save the dpi so the file thinks it is 96 when in fact it is something else (200 in my case). This is what you get for trusting somebody else's code |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Tue Mar 31, 2009 1:42 pm Post subject: |
|
|
neilw wrote: | This is what you get for trusting somebody else's code |
Own, untested code can be even worse ...
Glad to hear it's not a PDFsharp bug.
MigraDoc is fine if you have lots of text and don't want to manage page breaks.
You want one image per page, therefore I think PDFsharp may be appropriate. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
neilw
Joined: 31 Mar 2009 Posts: 3
|
Posted: Tue Mar 31, 2009 1:52 pm Post subject: |
|
|
Thanks again.
I see that pdfsharp can load from a Graphics object, whereas I have a Bitmap. Obviously it's quicker from memory than file, but is there a way to create a page from a Bitmap rather than a Graphics object, or is the conversion (Graphics.FromBitmap) almost cost free (I don't know what is actually involved in this call) and I'm worrying too much about nothing.
I'm just trying to make it as quick as possible as I have to convert about 9 million images to pdf files. It was about 200ms to load and convert my images to bitonal and save as tiff files, but using the migradoc as I originally did upped it to about 2 seconds (convert to bitonal and save as pdf). |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Wed Apr 01, 2009 11:33 am Post subject: |
|
|
JPEGs are simply copied into the PDF file, everything else needs to be converted. That conversion is my only contribution to PDFsharp and I hope it's quick (written in C#). _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
|