PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

PDF Merger getting Blank page
http://forum.pdfsharp.com/viewtopic.php?f=3&t=2742
Page 1 of 1

Author:  Luckbox72 [ Wed Feb 19, 2014 6:47 pm ]
Post subject:  PDF Merger getting Blank page

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.

Author:  Thomas Hoevel [ Thu Feb 20, 2014 9:25 am ]
Post subject:  Re: PDF Merger getting Blank page

If the problem persists with PDFsharp 1.32 then please provide the PDF files (or better provide an SSCCE) so we can test it.

Author:  Luckbox72 [ Thu Feb 20, 2014 7:27 pm ]
Post subject:  Re: PDF Merger getting Blank page

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

Author:  Luckbox72 [ Thu Feb 20, 2014 8:04 pm ]
Post subject:  Re: PDF Merger getting Blank page

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;
}

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/