Hey!
First thanks for offer PDFsharp. It works very well and it's definitively the best open source project respective modifying PDF with .NET/C#!
I have to put an PDF with an image (=background_filename) beneath another PDF with Text (=input_filename). I tried both options (draw XImage and XPdfForm) and always get a NullReferenceException (saying the object is null).
When I open 'background_filename' in Adobe Acrobat 9 and use the option
Document -> Background -> Add/Replace -> Source :: File :: 'background_filename'
and save it, the code work exactly as I want (XImage and XPdfForm).
So my two questions are: Is there a possibility to use an PDF file as Background which itself has not a Background (and use instead of that everything else 'above' the Background like images, text etc....) or is there a way to automate with C# the steps I made in Adobe Acrobat 9???
Thanks for your help!
My Code:
Code:
public void bg (string input_filename, string background_filename, string output_filename){
File.Copy(input_filename, output_filename, true);
PdfDocument pdf_doc_output = PdfReader.Open(output_filename);
//XPdfForm bg = XPdfForm.FromFile(background_filename);
XImage bg = XImage.FromFile(background_filename);
if (pdf_doc_output.Version < 14)
pdf_doc_output.Version = 14;
for (int idx = 0; idx < pdf_doc_output.Pages.Count; idx++)
{
PdfPage page = pdf_doc_output.Pages[idx];
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);
//XPdfForm img = XPdfForm.FromFile(background_filename);
XImage img = XImage.FromFile(background_filename);
gfx.DrawImage(img, 0,0);
}
pdf_doc_output.Save(output_filename);
Process.Start(output_filename);
}