PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Thu Feb 05, 2009 10:22 pm 
Offline

Joined: Thu Feb 05, 2009 10:13 pm
Posts: 4
I am trying to create a document with multiple pages.
Each page has the same basic template with the only thing changing
between each page is small portion of text (for an address).

I was able to generate the initial page but I am having trouble
figuring out how to just duplicate that page with the base
content without having to generate the whole page.

Does anybody have any suggestions?

Thanks in advance.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Feb 09, 2009 11:17 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
I'd try calling "Clone()" for that page.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Feb 09, 2009 4:06 pm 
Offline

Joined: Thu Feb 05, 2009 10:13 pm
Posts: 4
The clone method returns a pdfdictionary and not a pdfpage.
So if you could let me know how to convert a pdfdictionary to a pdfpage then I think it would work.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Feb 09, 2009 4:32 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
In C#:
Code:
PdfPage clone = (PdfPage)page.Clone();

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Feb 09, 2009 5:32 pm 
Offline

Joined: Thu Feb 05, 2009 10:13 pm
Posts: 4
Thanks. I did not know you could cast a pdfdictionary as a pdfpage.

I still have a problem though.
Even though I have a clone of the page it does not act as a separate object.
So when I add items to the original page it shows up on both pages.

I feel like I'm missing something simple here.

Any thoughts?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 10, 2009 9:12 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
I thought that Clone() would give you a deep copy.
Maybe there's just a little thing missing ...

Different approach:
Create a PDF document with your template.
Create it in a memory stream (see WebSamples / Clock how to do it).

Then create an XPdfForm from that stream.
Draw this on every page of your final document and add the address later.

You have 10 or 15 lines of code instead of a simple Clone(), but it should work.
We do a similar thing all the time: we use a page from a PDF file as stationary for other documents. I also did it when I needed a letter with 1600 different addresses.

But there may be more efficient solutions.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 18, 2009 7:53 pm 
Offline

Joined: Thu Feb 05, 2009 10:13 pm
Posts: 4
Thomas,

Thanks for the reply and idea for the different approach.

Do you think you could provide some sample code?

I tried the approach you suggested but I seem to be getting some errors
with the stream as it relates to the form.
I thought it would be more effective if just asked you for an example then
try and track down a working solution elsewhere.

Anything you can provide would be helpful.

Thanks in advance.


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 15, 2009 1:37 pm 
Offline

Joined: Tue Dec 15, 2009 1:28 pm
Posts: 1
Hi,
I have to duplicate pages on a document too.
And I have used the Clone() command

Code:
PdfPage newPage = (PdfPage)Content.Clone();


which is doesn't work has it is already said.

So I would like to use the method of Thomas Hoevel using a document and a memoryStream.
But I don't understand what i can do with a XPdfForm.

SO there is my code :

Code:
// Create new PDF document
PdfDocument document = new PdfDocument();
           
// Create new page
PdfPage page = document.AddPage(Content);
           
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
stream.Close();

//this command throw an Exception (The specified stream has no valid PDF file header.)
XPdfForm xpdf = XPdfForm.FromStream(stream);


This exception is thrown in XpdfForm.cs in the internal Ctor

Code:
    /// <summary>
    /// Initializes a new instance of the <see cref="XPdfForm"/> class from a stream.
    /// </summary>
    /// <param name="stream">The stream.</param>
    internal XPdfForm(Stream stream)
    {
      // Create a dummy unique path
      this.path = "*" + Guid.NewGuid().ToString("B");

      if (PdfReader.TestPdfFile(stream) == 0)
        throw new ArgumentException("The specified stream has no valid PDF file header.", "stream");

      this.externalDocument = PdfReader.Open(stream);
    }


Someone has an idea ?


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

All times are UTC


Who is online

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