Reputation: 102
I have a pdf having signature enabled, when i tried to render it using iTextSharp the signature got disappear. I have researched this issue on many platforms but not able to find any solution.
here is my code
private void BuildPDF(ref Document doc, ref PdfWriter writer)
{
int numberOfPages = 0;
int currentPageNumber = 0;
PdfImportedPage page;
int rotation;
PdfContentByte cb = writer.DirectContent;
ReportExecutionService rs = new ReportExecutionService(ReportServiceUrl, ReportServiceTimeout);
try
{
PdfReader reader2 = new PdfReader(ReportName);
currentPageNumber = 0;
numberOfPages = reader2.NumberOfPages;
while (currentPageNumber < numberOfPages)
{
currentPageNumber += 1;
doc.SetPageSize(PageSize.LETTER);
doc.NewPage();
page = writer.GetImportedPage(reader2, currentPageNumber);
rotation = reader2.GetPageRotation(currentPageNumber);
if ((rotation == 90) || (rotation == 270))
{
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader2.GetPageSizeWithRotation(currentPageNumber).Height);
}
else
{
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0);
}
}
}
catch
{
}
}
Please help me out, thanks in advance
Upvotes: 1
Views: 413
Reputation: 96029
What you call "rendering" appears to be "adding the content of each page to a new page of some target document".
If by "a pdf having signature enabled" you furthermore mean a pdf with an integrated digital signature with visualization, it is obvious that the signature will disappear in your "rendering": the signature visualization is not part of the page content, it is a widget annotation not copied by your "rendering"!
But even if it was copied, the situation wouldn't be better either: the signature would be located in a document it definitely didn't sign, so the signature would be invalid there, and I doubt you want a document with invalid signatures.
If you are only interested in the visualization, you should try and flatten the signed pdf before adding the contents to your target document.
That been said, if the overall task in your case is collecting the contents of multiple reports in a single pdf, your code doesn't use the appropriate iText classes anyways: for such a task one would use a PdfCopy
instead of a generic PdfWriter
, cf. this answer.
Upvotes: 1
Reputation: 1916
Use PdfCopy
to copy the objects other than content.
Note that if you happen to keep the signature appearance it will show up as invalid.
Upvotes: 0