logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Jan-Willem  
#1 Posted : Saturday, July 6, 2019 1:29:01 PM(UTC)
Jan-Willem

Rank: Newbie

Groups: Registered
Joined: 7/6/2019(UTC)
Posts: 2
Netherlands

How can I create an new Pdf from an C# List of PataGames.Pdf.Net.PdfPage objects.

I've the folowing code:

Code:
       List<PdfPage> myPDFPagesList = GetPDFPagesList(list);
       string myFulPathAndFileNameWithExtension = Path.Combine(myFullExtractionPath, myFileNAme + ".pdf");

            using (PdfDocument myNewPDF = PdfDocument.CreateNew())
            {

                for (int i = 0; i < myPDFPagesList.Count; i++)
                {
                    Patagames.Pdf.FS_SIZEF myNewSize = new Patagames.Pdf.FS_SIZEF(myPDFPagesList[i].Width, myPDFPagesList[i].Width);
                    myNewPDF.Pages.InsertPageAt(i, myNewSize);
                    myNewPDF.Pages[i].PageObjects.Add(myPDFPagesList[i].PageObjects[0]);
                    myNewPDF.Pages[i].GenerateContent(); 
                }

                myNewPDF.Save(myFulPathAndFileNameWithExtension, SaveFlags.NoIncremental);
            }


The pages are blanc. Also it seems complex since I already have PdfPages

Thanks in advance for your help

Edited by moderator Wednesday, July 10, 2019 8:07:53 AM(UTC)  | Reason: Not specified

Paul Rayman  
#2 Posted : Saturday, July 6, 2019 1:36:45 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 760

Thanks: 1 times
Was thanked: 92 time(s) in 91 post(s)
What is a "GetPDFPagesList"?
It seems you can just use the ImportPages method to copy pages from one document to another.
https://forum.patagames....merge-multiple-pdf-files
https://forum.patagames....plit-PDF-in-C--or-VB-Net
Jan-Willem  
#3 Posted : Tuesday, July 9, 2019 1:37:16 PM(UTC)
Jan-Willem

Rank: Newbie

Groups: Registered
Joined: 7/6/2019(UTC)
Posts: 2
Netherlands

Thanks for your response.

These examples all concern a PdfDocument. But my list contains PataGames.Pdf.Net.PdfPage objects. How can I create a Pdf document out of them?

Paul Rayman  
#4 Posted : Wednesday, July 10, 2019 8:04:21 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 760

Thanks: 1 times
Was thanked: 92 time(s) in 91 post(s)
Originally Posted by: Jan-Willem Go to Quoted Post
Thanks for your response.

These examples all concern a PdfDocument. But my list contains PataGames.Pdf.Net.PdfPage objects. How can I create a Pdf document out of them?



Where did you get them?
It seems you should use ImportPages instead. Like shown in the examples I have provided.

Just open one document, create new document and than import pages from one to another.



Concerning your code...

1. Why do you insert zero indexed page object only?
Code:
myNewPDF.Pages[i].PageObjects.Add(myPDFPagesList[i].PageObjects[0]);

2. You cannot insert the same object into multiple pages. You should clone it at least.
Code:
myNewPDF.Pages[i].PageObjects.Add(myPDFPagesList[i].PageObjects[0].Clone());


In any case, I believe that the ImportPages are more suitable for you.

Edited by user Wednesday, July 10, 2019 8:21:12 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.