PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 26, 2024 11:19 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon May 19, 2014 8:55 pm 
Offline

Joined: Mon May 19, 2014 5:16 pm
Posts: 3
I just found MigraDoc and PdfSharp this morning and am grateful such sw exist. I have a list of files that I am parsing through and adding to a PDF. When I add an existing pdf, it only displays the first page of the imported PDF, and adds margins, etc so what is displayed is way off center and missing half of the page that is displayed. I know I'm missing a few things but cannot find what I need, so I thought I would ask directly.

Code:
               Document doc = new Document();

                foreach (string path in archives)
                {
                    string r = GetFileExtension(path);
                    Section sec = doc.AddSection();
                    Paragraph para = sec.AddParagraph();

                    switch (r)
                    {
                        case "txt":
                        case "css":
                                TextReader sr = new StreamReader(path);
                                string _fileString = sr.ReadToEnd();
                                sr.Close();
                                sr.Dispose();                           
                                para.AddText(_fileString);                               
                            break;

                        case "png":
                        case "pdf":
                                sec.AddImage(path);
                            break;
                                   ...
                PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
                pdfRenderer.Document = doc;
                pdfRenderer.RenderDocument();
                pdfRenderer.PdfDocument.Save(fullFileName);


Again, this code "kinda" works, but not really. I also decided to go with MigraDoc after running into issues with importing text files being clipped after one page. MigraDoc handled that beautifully.

Please advise and thanx in advance.

I was also just informed the PDF's to merge may contain special fields, so I wonder id adding them as images will work, if not, what is the alternative to combining pdf and images and text?


Top
 Profile  
Reply with quote  
PostPosted: Tue May 20, 2014 8:44 am 
Offline
PDFsharp Guru
User avatar

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

AddImage() returns an Image object that allows you to set size, position, &c.

To have a page from a PDF file fill the whole page, you have to adjust size and position.

If there are several pages in the PDF file, then call AddImage() for each page. Add the page number to the file name ("foo.pdf#2" for second page).
Open the PDF file with PDFsharp to query the page count.

PDF pages will be added as PDF (vector format), not as rasterized images.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue May 20, 2014 12:39 pm 
Offline

Joined: Mon May 19, 2014 5:16 pm
Posts: 3
Thank you for the response. To satisfy all requirements I decided to create 2 PDF docs as I loop through the files. I create a PDFSharp doc to merge any called pdfs into, at the same time I create a MigraDoc for everything else. At the end I merge the MigraDoc into the PDFSharp doc. That way, they get all the original pdf functions up front, and any additional documents at the end. There may be a better way to do this but I cant think of any at the moment.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 332 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