PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 7:24 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Mar 31, 2009 12:32 pm 
Offline

Joined: Tue Mar 31, 2009 11:18 am
Posts: 3
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Mar 31, 2009 1:21 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Mar 31, 2009 1:25 pm 
Offline

Joined: Tue Mar 31, 2009 11:18 am
Posts: 3
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 ;)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Mar 31, 2009 1:42 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Mar 31, 2009 1:52 pm 
Offline

Joined: Tue Mar 31, 2009 11:18 am
Posts: 3
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).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Apr 01, 2009 11:33 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 412 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