PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 4:25 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Image Watermark
PostPosted: Wed Apr 16, 2008 10:05 am 
Offline

Joined: Wed Apr 16, 2008 9:42 am
Posts: 1
Hello,

I need your help :)

We get invoices from a customer in PDF format and need to add images (in German: Falzmarken) on the pages. A cutter reads those images and cuts the invoices at specific points. The printer works with continous paper and the cutter cuts the single pages.

My problem is that I cannot simply add images to a specific existing page without creating a new page. Maybe I do something wrong, but whenever I try to add something to an existing PDF, PDFSharp creates a new page.

I tried watermarking. With text it works fine, but with images it compiles and the output PDF is the same as the input PDF.


The questions are:
- (How) is it possible to do watermarking with images at a specific position and page?
- (How) is it possible to add images to existing pages without adding new pages?

Thanks in advance!

Christoph


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Apr 21, 2008 2:23 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hello!

I'm not sure what's the problem.

Adding watermarks to an existing file is quite simple:
Code:
PdfDocument document = PdfReader.Open(pdfFileName);
foreach (PdfPage page in document.Pages)
{
  XGraphics gfx = XGraphics.FromPdfPage(page);
[... do some drawing here ...]
}
document.Save(pdfFileName);


HTH

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Tue Nov 02, 2010 6:22 pm 
Offline

Joined: Mon Nov 01, 2010 7:39 pm
Posts: 7
[code][/code]

_________________
Vin


Last edited by sam on Wed Nov 03, 2010 2:04 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Wed Nov 03, 2010 8:40 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
sam wrote:
PDF is showing the image which looks so bad with few errors. Please help me.

If it looks bad, make it look good.

Or serious: how do you expect anybody to help you with the information you provide?
No image, no PDF, no error messages ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Wed Nov 03, 2010 2:02 pm 
Offline

Joined: Mon Nov 01, 2010 7:39 pm
Posts: 7
Thomas,

I tried attaching doc file with error message and it says extension is not allowed and wasn't sure how to show that screen shot.

Anyways now my watermark is working but the problem is it is showing Assersion failed error. If I click the ignore button on it (almost 4 times) my PDF is opening up with the watermark.

Message is Object type transformation must not be done with direct objects.

_________________
Vin


Last edited by sam on Wed Nov 03, 2010 7:16 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Wed Nov 03, 2010 2:15 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
sam wrote:
Message is Object type transformation must not be done with direct objects.

You can ignore that message (you can comment that Debug.Assert out).

You can attach images and ZIP files.

You can paste text into the message (e. g. using Quote or Code tags).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Wed Nov 03, 2010 3:00 pm 
Offline

Joined: Mon Nov 01, 2010 7:39 pm
Posts: 7
Thanks.

_________________
Vin


Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Thu Nov 04, 2010 4:56 am 
Offline

Joined: Mon Nov 01, 2010 7:39 pm
Posts: 7
Hi,
I am trying to add jpeg images to header and footer in migradoc.
I know how to scale the img. In pdfsharp using xgraphics and ximage. But not sure how to do in migradoc.

Thanks in advance for your reply.

_________________
Vin


Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Thu Nov 04, 2010 8:15 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
sam wrote:
But not sure how to do in migradoc.

When using MigraDoc, you specify the position, Width and Height.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Thu Nov 04, 2010 1:54 pm 
Offline

Joined: Mon Nov 01, 2010 7:39 pm
Posts: 7
I tried this. I can see the Image but the resolution is not good enough. Same case with the footer too. Is tehre a way that we can measure height and width width out loosing its resolution like the way we do in pdfsharp.

Code:
 Paragraph paragraph = section.Headers.Primary.AddParagraph();
            string HeaderPage1 =@"c/files/Images/header.jpeg";
            Image HeaderImage = section.Headers.Primary.AddImage(HeaderPage1);
             HeaderImage.RelativeHorizontal = RelativeHorizontal.Margin;
            HeaderImage.RelativeVertical = RelativeVertical.Margin;
            HeaderImage.LockAspectRatio = false;
            HeaderImage.ScaleWidth = 0.8;
           // HeaderImage.Height = new Unit(500, UnitType.Point);
          //  HeaderImage.Width = new Unit(500, UnitType.Point);
           // HeaderImage.Height = new Unit(15, UnitType.Centimeter);
            HeaderImage.Top = ShapePosition.Top;
            HeaderImage.Left = ShapePosition.Center;
            HeaderImage.WrapFormat.Style = WrapStyle.Through;
            paragraph.Format.Alignment = ParagraphAlignment.Center;


Thanks,

_________________
Vin


Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Thu Nov 04, 2010 2:32 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
sam wrote:
I can see the Image but the resolution is not good enough.

The image is used unaltered with all its pixels. Resolution depends on the size you draw it.
If you don't specify size then AFAIK size will be determined from the resolution.

Sorry, but I have no idea what your problem is.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Thu Nov 04, 2010 2:57 pm 
Offline

Joined: Mon Nov 01, 2010 7:39 pm
Posts: 7
Thomas,

I used the same code that showed you above and getting the PDF that I attached. Please compare 1st and 2nd page. The Image is not clear in the 1st one. Iam generating the 1st one and the 2nd page is the uploaded file from DB. You can also check the footer on the 1st page which is not clear.

Thanks

_________________
Vin


Last edited by sam on Thu Nov 04, 2010 7:15 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Image Watermark
PostPosted: Thu Nov 04, 2010 3:24 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
sam wrote:
Please compare 1st and 2nd page. The Image is not clear in the 1st one.

The pig on the second page has a higher resolution than the pig on the first page (DPI is double, so there are four times as many pixels).

Text in a bitmap looks ugly when you zoom in, text in PDF will always be smooth even at 6400 % zoom.

The Partner logo on the second page also has a higher resolution than the logo on the first page. So it seems you're comparing a page that PDFsharp created from low resolution images with a page that was created from higher resolution images. You can't blame that on PDFsharp.

Adobe's smoothing made no difference on my computer, so I presume this thread is completely unrelated:
viewtopic.php?p=2459#p2459

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 59 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