PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed May 23, 2018 4:40 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Feb 19, 2014 6:47 pm 
Offline

Joined: Wed Feb 19, 2014 6:40 pm
Posts: 3
I have an windows application that saves reports in pdf format. Then the app will merge certain pdfs together. The merge function was working I am currently using PDFSharp version 1.2.1269.0 and this is a Winforms .net c# 2008.

When I try to merge the two together I get one pdf fine but the second page is blank. If I change the order of the documents the first page becomes the blank page so I assume it has to do with the report.

If I tell it two merger the report that works to itself it gives me two pages of the same report which is correct. If I merge the report that does not work to itself I get 2 blank pages.

When I look at both reports individually they open fine in adobe reader.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 20, 2014 9:25 am 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2815
Location: Cologne, Germany
If the problem persists with PDFsharp 1.32 then please provide the PDF files (or better provide an SSCCE) so we can test it.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 20, 2014 7:27 pm 
Offline

Joined: Wed Feb 19, 2014 6:40 pm
Posts: 3
ok I downloaded and built 1.31 (this is a vs2008 project and the readme said to stay with 1.31 if in vs2008)then refreshed my reference in the project but I still get the same blank page.
To test I created a new sql report and just put 2 textboxes in it and filled them with text. When the app runs it creates the new report and when I break the code at
private void CopyPages(PdfDocument from, PdfDocument to)
{
for (int i = 0; i < from.PageCount; i++)
{
to.AddPage(from.Pages[i]);
}
}
it says the report has 3 pages which is correct.

In this code
PdfDocument one = PdfReader.Open(pdfPath, PdfDocumentOpenMode.Import);
PdfDocument two = PdfReader.Open(spiderDisclosurePath, PdfDocumentOpenMode.Import);
pdfPath.Replace(".pdf", "new.pdf");
PdfDocument outPdf = new PdfDocument();

CopyPages(one, outPdf);
CopyPages(two, outPdf);


outPdf.Save(pdfPath);

one is the document that shows on the final pdf two is the document that shows up blank on the final merge


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 20, 2014 8:04 pm 
Offline

Joined: Wed Feb 19, 2014 6:40 pm
Posts: 3
I have found that if I include the following code it will merge the 2 pdfs .

The following code was something I found a while back when I was trying to merger two different pdf versions together. MYM question is why would I need to do that when the pdfs are being dynamically created at the same time and then merged together, would they be the same version.

static private string WriteCompatiblePdf(string sFilename)
{
if (!Directory.Exists("c:\\Temp\\Converted\\"))
Directory.CreateDirectory("c:\\Temp\\Converted\\");
string sNewPdf = "c:\\Temp\\Converted\\" + Guid.NewGuid().ToString() + ".pdf";

iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(sFilename);

// we retrieve the total number of pages
int n = reader.NumberOfPages;
// step 1: creation of a document-object
iTextSharp.text.Document document = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1));
// step 2: we create a writer that listens to the document
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(sNewPdf, FileMode.Create));
//write pdf that pdfsharp can understand
writer.SetPdfVersion(iTextSharp.text.pdf.PdfWriter.PDF_VERSION_1_4);
// step 3: we open the document
document.Open();
iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
iTextSharp.text.pdf.PdfImportedPage page;

int rotation;

int i = 0;
while (i < n)
{
i++;
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
// step 5: we close the document
document.Close();
return sNewPdf;
}


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
Powered by phpBB® Forum Software © phpBB Group