PDF Viewer not showing file content
1. I have added a PDF Connector and specified the File Name.
2. Created a PDF Viewer and specified the Connector created in step 1
3. But the viewer does not show the content of the file.
4. Tried to Highlight Line/Segment/Word. But got the following error message:
System.InvalidOperationException: PDF File chery.pdf cannot be opened.
at OpenSpan.Pdf.PdfConnector.PdfConnector.EnsureOpen()
at OpenSpan.Pdf.PdfConnector.PdfConnector.get_Pages()
at OpenSpan.Pdf.PdfControl.PdfViewer.HighlightLines()
at OpenSpan.Pdf.PdfControl.PdfViewer.btnHighlightLines_Click(Object sender, EventArgs e)
5. If I put the above file name directly in the viewer, the file content shows up in the PDF Viewer.
This PDF file have 17 pages. What is wrong here, or how can I fix the issue to load and show the pages through PDF Connector and PDF Viewer
Upon reviewing the associated Support Request, the Issue was resolved using the following script:
using iTextSharp.text;
using iTextSharp.text.pdf;
public void newMethod1(string filename)
{
//copy pdf to following folder
string path = @"C:/Temp/"+filename; //or any other path to store the new pdf.
//if pdf requires password uncomment the line below
//byte[] pass = System.Text.ASCIIEncoding.ASCII.GetBytes("4123");
PdfReader.unethicalreading = false;
//location of pdf
PdfReader pdf = new PdfReader("(PATH WHERE ORIGINAL PDF ARE STORED)"+filename);
using(MemoryStream memory = new MemoryStream())
{
PdfStamper stamper = new PdfStamper(pdf, memory);
stamper.Close();
pdf.Close();
File.WriteAllBytes(path, memory.ToArray());
}
}
Upon reviewing the associated Support Request, the Issue was resolved using the following script:
using iTextSharp.text;
using iTextSharp.text.pdf;
public void newMethod1(string filename)
{
//copy pdf to following folder
string path = @"C:/Temp/"+filename; //or any other path to store the new pdf.
//if pdf requires password uncomment the line below
//byte[] pass = System.Text.ASCIIEncoding.ASCII.GetBytes("4123");
PdfReader.unethicalreading = false;
//location of pdf
PdfReader pdf = new PdfReader("(PATH WHERE ORIGINAL PDF ARE STORED)"+filename);
using(MemoryStream memory = new MemoryStream())
{
PdfStamper stamper = new PdfStamper(pdf, memory);
stamper.Close();
pdf.Close();
File.WriteAllBytes(path, memory.ToArray());
}
}
Also need to have the itextsharp.dll in openspan installation folder, and referenced in project.
After adding the script, clean and rebuild so that the script component allows the filename to be passed to the script.
Add a script block from toolbox and specify the filename of the original pdf, connect this and its result to the pdfConnector.Filename block.
Then the pdf specified in the filename will be opened through pdfConnector (after invoking using button for example.)