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:35 pm

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 Apr 15, 2014 7:21 am 
Offline

Joined: Tue Apr 15, 2014 6:51 am
Posts: 7
Hi,

I have a problem with "Prepend" option on some PDF files.

- Doc1.pdf is created from Word
- Doc2.pdf is created from a TIFF Image

Doc1 is Ok "My text 2014" whith blue DrawRectangle are visible
Doc2 is not Ok "My text 2014" whith blue DrawRectangle are selectable but invisible


Can you help me
I have attached two PDF files
my code below ...
Thank you

const string text = "My text 2014";
PdfDocument document = PdfReader.Open(fileNamePDF, PdfDocumentOpenMode.Modify);
foreach (PdfPage page in document.Pages)
{
XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold);
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);
XTextFormatter tf = new XTextFormatter(gfx);
XRect rect = new XRect(450, 1, 70, 20);
gfx.DrawRectangle(XBrushes.Blue, rect);
tf.Alignment = XParagraphAlignment.Right;
gfx.DrawString(text, font, XBrushes.Black,rect,XStringFormats.TopLeft);
}


Attachments:
Doc1and2.zip [99.09 KiB]
Downloaded 359 times
Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 15, 2014 8:19 am 
Offline
PDFsharp Guru
User avatar

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

It's not a bug, it's a feature. :wink:

Doc1 contains black text on a transparent page - the prepended logo shows through.

Doc2 contains an image that fills the whole page and hides the prepended logo. Try Append instead of Prepend to place your watermark above the original content (and not below it).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 15, 2014 3:57 pm 
Offline

Joined: Tue Apr 15, 2014 6:51 am
Posts: 7
Hi,

Thank you for your answer

I try with "Append" is better, my Blue Rectangle is visible but not "my text 2014"

My code is the same, i just modified "XGraphicsPdfPageOptions.Prepend" by "XGraphicsPdfPageOptions.Append"

I have attached the new PDF files "Doc2 with Append.pdf"

TY


Attachments:
Doc2 whith Append.zip [19.91 KiB]
Downloaded 363 times
Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 17, 2014 2:48 pm 
Offline

Joined: Tue Apr 15, 2014 6:51 am
Posts: 7
Hi,

Have you been able to analyze my problem ?

Thank you


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 17, 2014 3:55 pm 
Offline
PDFsharp Guru
User avatar

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

I tried the following code successfully:
Code:
string file = @"D:\PDFsharp\Prepend404\Doc2 whith Append.pdf";
string copy2 = @"D:\PDFsharp\Prepend404\doc2$$$$$$.pdf";
const string text = "My text 2014";
PdfDocument document = PdfReader.Open(file, PdfDocumentOpenMode.Modify);
foreach (PdfPage page_ in document_.Pages)
{
    XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold);
    XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);
    XTextFormatter tf = new XTextFormatter(gfx);
    XRect rect = new XRect(250, 1, 70, 20);
    gfx.DrawRectangle(XBrushes.Blue, rect);
    tf.Alignment = XParagraphAlignment.Right;
    gfx.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);
}
document_.Save(copy2);


I only had your modified Doc2.pdf and the other file to try it with.

As a hack: run your code twice and the watermark should show.

Or give me the unmodified source of Doc2.pdf and I'll have a look after Easter.

BTW: you probably meant to use tf.DrawString(). I didn't try it, but it should make no difference.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 19, 2014 3:57 pm 
Offline

Joined: Tue Apr 15, 2014 6:51 am
Posts: 7
Hi,

I run my code twice and the text appears !!?
It's cool

If you want try whith my doc2 no modified, I have attached the PDF files "Doc2.pdf"

Thank you


Attachments:
doc2.zip [18.85 KiB]
Downloaded 372 times
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 373 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