Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu May 11, 2017 6:10 pm

Hi,
Is there any way in C#/Spire.PDF to detect if a pdf file is actually a Portfolio?

Thanks,
Rob

saskpower
 
Posts: 8
Joined: Mon Apr 03, 2017 2:40 pm

Fri May 12, 2017 1:35 am

Dear Rob,

Thanks for your inquiry.
Sorry that at present Spire.PDF doesn't support that, but we already added the new feature into our schedule. Once it is finished, we will inform you immediately.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue May 16, 2017 3:48 pm

Hi
I found a solution using the current version.
Once I realized that the portfolio file was using attachments, the solution was fairly simple.
I'm posting the code in case anyone else has the same issue:

private void btnOpenPDFs_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow grdRowPDF in grdPDFprops.SelectedRows)
{
try
{
//Select the files I want to process from a data grid
//The data in the grid is filtered by the contects of the filename (*.pdf)
DataGridViewRow selectedRowPDF = grdPDFprops.Rows[grdRowPDF.Index];

//I'm working off a database but it would be just as simple to work of a directory listing
string strFile = Convert.ToString(selectedRowPDF.Cells["FileName"].Value);
string strExt = Convert.ToString(selectedRowPDF.Cells["Extention"].Value);
string strPath = Convert.ToString(selectedRowPDF.Cells["Path"].Value);

//location to store the original portfolio file once processed
string strDestPath = strPath + @"Portfolios\";

//Open the pdf and determine if it has attachments
PdfDocument docPDF = new PdfDocument();
docPDF.LoadFromFile(strPath + strFile);
PdfAttachmentCollection docPDFAttached = docPDF.Attachments;
PdfAttachment docAttach = null;

//If attachments extract them to the same directory as the portfolio was stored
if (docPDF.Attachments.Count > 0)
{
selectedRowPDF.Cells["Portfolio"].Value = docPDF.Attachments.Count;
foreach (PdfAttachment pdfDoc in docPDF.Attachments)
{
string strFileAttachment = pdfDoc.FileName;
docAttach = pdfDoc;
if (docAttach != null)
{
File.WriteAllBytes(strPath + docAttach.FileName, docAttach.Data);
}
}
}
docPDF.Close();

//move the portfolio and update my database and the grid
System.IO.File.Move(strPath + strFile, strDestPath + strFile);
UpdateScannedFiles(strFile, Convert.ToInt16(selectedRowPDF.Cells["Portfolio"].Value));
selectedRowPDF.Cells["Inspected"].Value = true;
grdPDFprops.Refresh();
}
catch (Exception exPDF)
{
string strStatus = exPDF.ToString();
}
}
MessageBox.Show ("Done");
}

Thanks,
Rob

saskpower
 
Posts: 8
Joined: Mon Apr 03, 2017 2:40 pm

Wed May 17, 2017 1:51 am

Dear Rob,

Thanks for sharing.
In addition, the new feature has been done, it is more convenient to detect if a pdf file is actually a Portfolio. Here is the hotfix.
https://www.e-iceblue.com/downloads/Tem ... .9.103.zip
And sample code for your reference.
Code: Select all
            PdfDocument pdf = new PdfDocument(FilePath + "sample.pdf");
            bool value = pdf.IsPortfolio;

If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri May 19, 2017 3:09 pm

Thanks for the quick patch Betsy.

You have one of the best Customer Support Departments I've ever seen.

Thanks so much!
Rob

saskpower
 
Posts: 8
Joined: Mon Apr 03, 2017 2:40 pm

Mon May 22, 2017 1:44 am

Appreaciate it. Please contact us if you have any questions or needs.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Aug 17, 2017 3:24 am

I have the same issue. These discussion really helped me to solve my own problem.
Last edited by Uriah090 on Tue Sep 26, 2017 1:57 am, edited 1 time in total.

Uriah090
 
Posts: 1
Joined: Thu Aug 17, 2017 3:17 am

Thu Aug 17, 2017 3:54 am

Hello Uriah090,

Glad to hear that.
Please feel free to contact us if you need any help.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF