PDA

View Full Version : Autosolved - basic working with PDF



KIVan
11-19-2010, 07:41 AM
Hello, guys. I registered to get help for reading\writing PDF metadata from Excel, wanted to use search before making a topic, but since than found a good lib on the net that does the trick - complete with knowledge base, forum and reference - quickpdflibrary. You'll have to google it yourself, since i cant post links yet. They have a Lite version for free, it contains only a small amount of functions - but it worked for me.

The problem of working with metadata drove me crazy for a week now - i could do it using Acrobat, but needed to find a way to do that without it. Didn't want any large lib, since i only needed few functions (+ they are $$$). This lib helped me a lot, hope it helps you to.

P.S. I think this post kind of looks like an ad, but since i'm recommending the free version - i guess its ok. Sorry if it violates any forum rules.
P.P.S. Anyone knows other good libs for PDF that work with Excel? I tryed libharu, but couldn't get it to register at references.

Bob Phillips
11-19-2010, 09:50 AM
I am afraid I think life is far too short to write code to read PDFs. There are good, reasonably priced, apps out there that already do it, and output to Word, Excel etc. That's the way I go.

KIVan
11-19-2010, 02:50 PM
I don't need to read pdfs - I need to write and read their metadata. Paper documents are scanned to PDFs, then references to them are added to an index in Excel, with fields like date, type, sender, recipient, synopsis, etc. In the future this files may be tossed around, or index may be lost, so all that data also gets written to their "keywords" section. Whenever an index is needed, VBA will scan a specified folder for any pdfs with a certain marker and read back info from them.

Aussiebear
11-19-2010, 10:07 PM
What does "Autosolved" mean? I've read the thread and fail to see where a solution has been arrived at, provided or even discussed?

KIVan
11-20-2010, 03:18 AM
Well - the question was - how to work with PDF from Excel without having to install Acrobat. I particularly needed access to metadata. The solution - QuickPDFLibrary "lite". The code that worked for me is shown below (mind that you have to download and register the lib as per instructions on their site). Its a proof of concept, and ill start working on the real thing on Monday.
P.S. This code is a reworked sample from the lib authors site.

Option Explicit
Private Sub metadataWriteTest()

Dim ClassName
Dim FileName

ClassName = "QuickPDFLite0719.PDFLibrary"

FileName = "C:\Program Files\Quick PDF Library\Lite\License.pdf"

Dim QP
Dim FromDocumentID

Set QP = CreateObject(ClassName)

Call QP.LoadFromFile(FileName)
FromDocumentID = QP.SelectedDocument()
MsgBox QP.SetInformation(4, "Test went ok")
MsgBox QP.SaveToFile(FileName)

End Sub

Private Sub metadataReadTest()

Dim ClassName
Dim FileName

ClassName = "QuickPDFLite0719.PDFLibrary"

FileName = "C:\Program Files\Quick PDF Library\Lite\License.pdf"

Dim QP
Dim FromDocumentID
Dim MsgText

Set QP = CreateObject(ClassName)

Call QP.LoadFromFile(FileName)
FromDocumentID = QP.SelectedDocument()
MsgText = QP.GetInformation(4)

MsgBox MsgText

End Sub

Aussiebear
11-20-2010, 03:57 AM
Thank you for posting the solution

Bob Phillips
11-20-2010, 04:07 AM
If you have Excel 2007, you can write directly to PDF. IN 2003, I use PDF Creator.

KIVan
11-20-2010, 05:21 AM
If you have Excel 2007, you can write directly to PDF.

Could you please elaborate on that? Is metadata accessible (boy that would be great)? A link to more info maybe?

P.S. Or did you mean "save as PDF"?.

Bob Phillips
11-20-2010, 06:29 AM
Yes, I meant save the spreadsheet as a PDF file.

KIVan
11-20-2010, 10:08 AM
That is the exact reason I decided to post this info here - I googled for about 5-7 hours total time, and all manuals I found were on how to make PDF from Excel, but I needed to work with the PDFs I already have. So I decided to post this info here - I hope anyone with the same problem will come across this post in less than 5 hours.

P.S. The reference manual mentioned above contains a description for each function available in the lib for anyone with an even less trivial task in mind.

Paul_Hossler
11-21-2010, 07:13 AM
XLD --



If you have Excel 2007, you can write directly to PDF


I thought that the MS Addin "Save to PDF and XPS" was required

Is there a way to do that without the add in?

2010 has


wb.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sCML_Workbook, Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False


Which works very well, but I need a way to 'save as' PDF's without assuming that the add in is loaded

Paul

Bob Phillips
11-21-2010, 08:22 AM
You don't need the addin. It is built-in with 2010, and was in 2007 SP2 on.

Paul_Hossler
11-21-2010, 08:56 AM
XLD -- could I impose on you for a bit of 2007/SP2 code to generate a PDF to replace the non-2010 code following the the 'Else' below?

I'd like to have PDF's regardless of version. I only hve 2010 on my comp, and I'll have to get someone at work to verify my 2007 version.


Call ParsePath(ThisWorkbook.FullName, F, n, E)

'2010 make PDF
If CInt(Application.Version) >= 14 Then

'build the CML WB file name
sCML_Workbook = F & Application.PathSeparator & n & ".CML.pdf"

'delete existing CML workbook
Call RecycleBinFile(sCML_Workbook)

'export as a PDF file
wb.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sCML_Workbook, Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False

'Not 2010 so save as XLSX
Else

'build the CML WB file name
sCML_Workbook = F & Application.PathSeparator & n & ".CML.xlsx"

'delete existing CML workbook
Call RecycleBinFile(sCML_Workbook)

'export as a XLSX file
wb.SaveAs Filename:=sCML_Workbook, FileFormat:=xlOpenXMLWorkbook

End If


wb.Close (False)


Thanks

Paul

Bob Phillips
11-21-2010, 09:46 AM
It's the same as the 2010 code.

Paul_Hossler
11-21-2010, 11:10 AM
That does make it easy. Thanks

Paul