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

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
Jan-Willem  
#1 Posted : Saturday, July 6, 2019 10:29:01 AM(UTC)
Quote
Jan-Willem

Rank: Newbie

Groups: Registered
Joined: 7/6/2019(UTC)
Posts: 4
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 5:07:53 AM(UTC)  | Reason: Not specified

Paul Rayman  
#2 Posted : Saturday, July 6, 2019 10:36:45 AM(UTC)
Quote
Paul Rayman

Rank: Administration

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

Thanks: 10 times
Was thanked: 133 time(s) in 130 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 10:37:16 AM(UTC)
Quote
Jan-Willem

Rank: Newbie

Groups: Registered
Joined: 7/6/2019(UTC)
Posts: 4
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 5:04:21 AM(UTC)
Quote
Paul Rayman

Rank: Administration

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

Thanks: 10 times
Was thanked: 133 time(s) in 130 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 5:21:12 AM(UTC)  | Reason: Not specified

Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.