Edit PDF in iLogic

Edit PDF in iLogic

pavol_krasnansky
Enthusiast Enthusiast
1,076 Views
7 Replies
Message 1 of 8

Edit PDF in iLogic

pavol_krasnansky
Enthusiast
Enthusiast

Hello

 

I need to add text (stamp) into exist PDF file in iLogic rule on computer without Adobe Reader Professional (I cannot create object "AcroExch.App") Does way exist?

 

Thank you

0 Likes
Accepted solutions (1)
1,077 Views
7 Replies
Replies (7)
Message 2 of 8

Mark.Lancaster
Consultant
Consultant

@pavol_krasnansky 

 

Use the Inventor customization forum for this https://forums.autodesk.com/t5/inventor-customization/bd-p/120

 

I will have the moderator relocate your posting there to best suit your needs.

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 3 of 8

machiel.veldkamp
Collaborator
Collaborator

You should have adobe Pro installed.

This is a merge pdf function... ArrayFilePaths should contain paths (C:/.../file.pdf) to which PDF's should be merged.

 

Sub MergePdfs(arrayFilePaths)
Logger.Info("MergePDFs")
Try
AdobeApp = CreateObject("Acroexch.app")
primaryDoc = CreateObject("AcroExch.PDDoc")
Catch
MessageBox.Show("Adobe Pro required. Canceling PDF Merge", "MergePdfs")
Logger.Info("Adobe Pro required. Canceling PDF Merge")

Exit Sub
End Try


' Copy primary doc and open the copy.
' arrayFilePaths(0)' copy this file and open the copy?

oOriginalName = arrayFilePaths(0)
oCopyName = Left(arrayFilePaths(0), Len(arrayFilePaths(0)) -4) & "-PACKET.pdf"

System.IO.File.Copy(oOriginalName, oCopyName)
arrayFilePaths(0) = oCopyName

OK = primaryDoc.Open(arrayFilePaths(0))
' Logger.Info("PRIMARY DOC OPENED & PDDOC SET: " & OK)

For arrayIndex = 1 To UBound(arrayFilePaths)
numPages = primaryDoc.GetNumPages() -1

sourceDoc = CreateObject("AcroExch.PDDoc")
OK = sourceDoc.Open(arrayFilePaths(arrayIndex))
' Logger.Info("SOURCE DOC OPENED & PDDOC SET: " & OK)

numberOfPagesToInsert = sourceDoc.GetNumPages

OK = primaryDoc.InsertPages(numPages, sourceDoc, 0, numberOfPagesToInsert, False)
' Logger.Info("PAGES INSERTED SUCCESSFULLY: " & OK)

OK = primaryDoc.Save(PDSaveFull, arrayFilePaths(0))
' Logger.Info("PRIMARYDOC SAVED PROPERLY: " & OK)

sourceDoc = Nothing

Next arrayIndex

primaryDoc = Nothing
AdobeApp.Exit
AdobeApp = Nothing
End Sub

 

Hope it helps.

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
Message 4 of 8

pavol_krasnansky
Enthusiast
Enthusiast

Thank you for answers
I want to find some solutions with using for example free DLL libraries or something similar. Adobe Reader Professional is not free software.

0 Likes
Message 5 of 8

machiel.veldkamp
Collaborator
Collaborator

Ah. Well I don't have that example. I just know that Adobe Pro can do it with their extensive API. 

 

Good luck, I hope that you find what you're looking for.

 

Could you reply if you eventually do find a free solution?

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 6 of 8

pavol_krasnansky
Enthusiast
Enthusiast

Yes of course, I will publish solution, if I find somethínk.

Message 7 of 8

pavol_krasnansky
Enthusiast
Enthusiast

Hello


I found solutions with using libraries PDFsharp:
www.pdfsharp.net

 

AddReference "PdfSharp.dll"
AddReference "System.Drawing.dll"

 

' Opening existing PDF
Dim oDoc_PDF As PdfSharp.Pdf.PdfDocument = PdfSharp.Pdf.IO.PdfReader.Open("C:\TEMP\Test.pdf", PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify)

 

' Set font encoding to unicode
Dim oFont_Options As PdfSharp.Drawing.XPdfFontOptions = New PdfSharp.Drawing.XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode, PdfSharp.Pdf.PdfFontEmbedding.Always)

 

For i = 0 To oDoc_PDF.PageCount - 1

' Get an object of PDF sheet
Dim oSheet_PDF As PdfSharp.Pdf.PdfPage = oDoc_PDF.Pages(i)

' Get a size of PDF Sheet
Dim Width_Of_PDF_Sheet As Integer = oSheet_PDF.Width
Dim Height_Of_PDF_Sheet As Integer = oSheet_PDF.Height

' Get an XGraphics object for drawing
Dim oGfx As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(oSheet_PDF)

' Get an object of font for inserted text
Dim oFont As PdfSharp.Drawing.XFont = New PdfSharp.Drawing.XFont("Arial", 20, PdfSharp.Drawing.XFontStyle.Regular, oFont_Options)

' Inserting text into sheet of PDF
oGfx.DrawString("Hello Autodesk Inventor!", oFont, PdfSharp.Drawing.XBrushes.Black, Width_Of_PDF_Sheet / 2, Height_Of_PDF_Sheet / 2, PdfSharp.Drawing.XStringFormats.Center)

Next

 

' Save and close PDF
oDoc_PDF.Save("C:\TEMP\Test.pdf")
' oDoc_PDF.Save("C:\TEMP\Test2.pdf")
oDoc_PDF.Close()
oDoc_PDF = Nothing

0 Likes
Message 8 of 8

pavol_krasnansky
Enthusiast
Enthusiast
Accepted solution

Hello


I found solutions with using libraries PDFsharp:
www.pdfsharp.net

 

AddReference "PdfSharp.dll"
AddReference "System.Drawing.dll"

' Opening existing PDF
Dim oDoc_PDF As PdfSharp.Pdf.PdfDocument = PdfSharp.Pdf.IO.PdfReader.Open("C:\TEMP\Test.pdf", PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify)

' Set font encoding to unicode
Dim oFont_Options As PdfSharp.Drawing.XPdfFontOptions = New PdfSharp.Drawing.XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode, PdfSharp.Pdf.PdfFontEmbedding.Always)

For i = 0 To oDoc_PDF.PageCount - 1
	
	' Get an object of PDF sheet
	Dim oSheet_PDF As PdfSharp.Pdf.PdfPage = oDoc_PDF.Pages(i)
	
	' Get a size of PDF Sheet
	Dim Width_Of_PDF_Sheet As Integer = oSheet_PDF.Width
	Dim Height_Of_PDF_Sheet As Integer = oSheet_PDF.Height
	
	' Get an XGraphics object for drawing
	Dim oGfx As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(oSheet_PDF)
	
	' Get an object of font for inserted text
	Dim oFont As PdfSharp.Drawing.XFont = New PdfSharp.Drawing.XFont("Arial", 20, PdfSharp.Drawing.XFontStyle.Regular, oFont_Options)
	
	' Inserting text into sheet of PDF
	oGfx.DrawString("Hello Autodesk Inventor!", oFont, PdfSharp.Drawing.XBrushes.Black, Width_Of_PDF_Sheet / 2, Height_Of_PDF_Sheet / 2, PdfSharp.Drawing.XStringFormats.Center)
	
Next

' Save and close PDF
oDoc_PDF.Save("C:\TEMP\Test.pdf")
' oDoc_PDF.Save("C:\TEMP\Test2.pdf")
oDoc_PDF.Close()
oDoc_PDF = Nothing

 

0 Likes