@VeryDOC SDK & COM & CLI

Replace text and string in PDF file by PDF Parser & Modify SDK from C#, VB.NET and ASP.NET

PDF Parser & Modify SDK for .NET can be downloaded and purchased from following web page,

 

https://www.verydoc.com/pdfparsersdk.html

 

You can use following VB.NET code to replace text contents in PDF page, you can port this VB.NET code to C# code easily.

 

The entire example is included in this download package,

 

https://www.verydoc.com/pdfparsersdk.zip

 

Imports System

Imports System.IO

Imports System.Text

Imports System.Drawing

Imports System.Drawing.Imaging

 

Public Class Form1

 

    Private Declare Function VeryPDF_PDFParserSDK Lib "pdfparsersdk2.dll" (ByVal lpPDFFile As String, ByVal lpOutFile As String, ByVal lpOptions As String) As Integer

    Private Declare Function VeryPDF_PDFParserSDKFromMemory Lib "pdfparsersdk2.dll" (ByRef lpPDFData As Byte, ByVal nDataLen As Integer, ByVal lpOutFile As String, ByVal lpOptions As String) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_GetHandle Lib "pdfparsersdk2.dll" (ByVal lpPDFFile As String, ByVal lpOptions As String) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_GetCount Lib "pdfparsersdk2.dll" (ByVal hPDFParserData As Integer) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_GetImageLength Lib "pdfparsersdk2.dll" (ByVal hPDFParserData As Integer, ByVal nIndex As Integer) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_GetImageData Lib "pdfparsersdk2.dll" (ByVal hPDFParserData As Integer, ByVal nIndex As Integer, ByRef lpData As Byte, ByVal nBufLen As Integer) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_GetTextInfoLength Lib "pdfparsersdk2.dll" (ByVal hPDFParserData As Integer, ByVal nIndex As Integer) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_GetTextInfoData Lib "pdfparsersdk2.dll" (ByVal hPDFParserData As Integer, ByVal nIndex As Integer, ByRef lpData As Byte, ByVal nBufLen As Integer) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_Free Lib "pdfparsersdk2.dll" (ByVal hPDFParserData As Integer) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_GetPageCount Lib "pdfparsersdk2.dll" (ByVal lpPDFFile As String) As Integer

    Private Declare Function VeryPDF_PDFParserSDK_GetAllPagesCount Lib "pdfparsersdk2.dll" (ByVal hPDFParserData As Integer) As Integer

 

    Private Declare Function VeryPDF_ModifyPDF_OpenFile Lib "pdfparsersdk2.dll" (ByVal lpInPDFFile As String, ByVal lpOutPDFFile As String) As Integer

    Private Declare Function VeryPDF_ModifyPDF_CloseFile Lib "pdfparsersdk2.dll" (ByVal hPDF As Integer) As Integer

    Private Declare Function VeryPDF_ModifyPDF_ModifyText Lib "pdfparsersdk2.dll" (ByVal hPDF As Integer, ByVal nPage As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal lpOldText As String, ByVal lpNewText As String) As Integer

 

    Private Declare Sub VeryPDF_ModifyPDF_SetCode Lib "pdfparsersdk2.dll" (ByVal lpCode As String)

 

    Public Function Byte2Image(ByVal ByteArr() As Byte) As Image

        Dim NewImage As Image = Nothing

        Dim ImageStream As MemoryStream

        Try

            If ByteArr.GetUpperBound(0) > 0 Then

                ImageStream = New MemoryStream(ByteArr)

                NewImage = Image.FromStream(ImageStream)

            Else

                NewImage = Nothing

            End If

        Catch ex As Exception

            NewImage = Nothing

        End Try

        Byte2Image = NewImage

    End Function

 

    Public Function Image2Byte(ByRef NewImage As Image) As Byte()

        Dim ImageStream As MemoryStream

        Dim ByteArr() As Byte = Nothing

        Try

            ReDim ByteArr(0)

            If NewImage IsNot Nothing Then

                ImageStream = New MemoryStream

                NewImage.Save(ImageStream, ImageFormat.Png)

                ReDim ByteArr(CInt(ImageStream.Length - 1))

                ImageStream.Position = 0

                ImageStream.Read(ByteArr, 0, CInt(ImageStream.Length))

            End If

        Catch ex As Exception

        End Try

        Image2Byte = ByteArr

    End Function

 

   

 

    Private Sub LoadPDFFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadPDFFile.Click

        OpenFileDialog1.Title = "Please Select a File"

        OpenFileDialog1.InitialDirectory = Application.StartupPath()

        OpenFileDialog1.ShowDialog()

    End Sub

 

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

        Dim strm As System.IO.Stream

        strm = OpenFileDialog1.OpenFile()

        PDFFileName.Text = OpenFileDialog1.FileName.ToString()

        If Not (strm Is Nothing) Then

            'insert code to read the file data

            strm.Close()

 

            ParserPDFFile()

        End If

    End Sub

 

    Private Sub ParserPDFFile()

 

        Dim nRet As Integer

        Dim strOptions As String

        Dim strInPDFFile As String

        Dim strOutFile As String

        Dim strLogMsg As String

        Dim nDPI As Integer = 300

 

        'Render PDF pages to PNG image files first

        strInPDFFile = PDFFileName.Text

        strOutFile = Application.StartupPath() & "\out.png"

        strOptions = "-r 72 -html -$ XXXXXXXXXXXXXXXXXXXXXX"

        nRet = VeryPDF_PDFParserSDK(strInPDFFile, strOutFile, strOptions)

        strLogMsg = strInPDFFile & vbCrLf & strOutFile & vbCrLf & strOptions & vbCrLf & "nRet = " & Str(nRet)

        MsgBox(strLogMsg)

 

        Dim strOutHTMLFile As String = Application.StartupPath() & "\out_pg_0001.htm"

        Dim Reader As StreamReader = File.OpenText(strOutHTMLFile)

        Dim strFileText As String = Reader.ReadToEnd()

        Reader.Close()

        HTMLContents.Text = strFileText

        WebBrowser1.Url = New Uri(Path.Combine("file://", strOutHTMLFile))

    End Sub

    Private Sub DEMO_ReplaceTextInPDFDirectly_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DEMO_ReplaceTextInPDFDirectly.Click

 

        Dim nRet As Integer

        Dim strOptions As String

        Dim strInPDFFile As String

        Dim strOutFile As String

        Dim strLogMsg As String

        Dim nDPI As Integer = 300

 

        'Render PDF pages to PNG image files first

        strInPDFFile = Application.StartupPath() & "\F_COC.pdf"

        strOutFile = Application.StartupPath() & "\out.png"

        strOptions = "-r " & CStr(nDPI) & " -html -$ XXXXXXXXXXXXXXXXXXXXXX"

        nRet = VeryPDF_PDFParserSDK(strInPDFFile, strOutFile, strOptions)

        strLogMsg = strInPDFFile & vbCrLf & strOutFile & vbCrLf & strOptions & vbCrLf & "nRet = " & Str(nRet)

        MsgBox(strLogMsg)

 

        'default DPI is 72DPI in PDF file, so you need calculate position by 72DPI,

        'you can read the text contents and position from output HTML file

        Dim x, y, w, h, hPDF, bRet, nPage As Integer

        Dim strOldText, strNewText As String

 

        VeryPDF_ModifyPDF_SetCode("Your License Key for ModifyPDF SDK")

        strOutFile = Application.StartupPath() & "\modified.pdf"

        hPDF = VeryPDF_ModifyPDF_OpenFile(strInPDFFile, strOutFile)

 

        'Replace horizontal text contents

        nPage = 1

        x = 452 * 72.0 / nDPI

        y = 809 * 72.0 / nDPI

        w = 150 * 72.0 / nDPI

        h = 35 * 72.0 / nDPI

        strOldText = "Voucher"

        strNewText = "VeryPDF1"

        bRet = VeryPDF_ModifyPDF_ModifyText(hPDF, nPage, x, y, w, h, strOldText, strNewText)

 

        'Replace vertical text contents

        nPage = 1

        x = 191 * 72.0 / nDPI

        y = 199 * 72.0 / nDPI

        w = 70 * 72.0 / nDPI

        h = 559 * 72.0 / nDPI

        strOldText = "PV91039100375"

        strNewText = "VeryPDF12"

        bRet = VeryPDF_ModifyPDF_ModifyText(hPDF, nPage, x, y, w, h, strOldText, strNewText)

 

        VeryPDF_ModifyPDF_CloseFile(hPDF)

        MsgBox("Process completed." & vbCrLf & "VeryPDF_ModifyPDF_ModifyText() return: " & CStr(bRet))

    End Sub

 

    Private Sub Replace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Replace.Click

        'default DPI is 72DPI in PDF file, so you need calculate position by 72DPI,

        'you can read the text contents and position from output HTML file

        Dim x, y, w, h, hPDF, bRet, nPage As Integer

        Dim strOldText, strNewText As String

 

        VeryPDF_ModifyPDF_SetCode("Your License Key for ModifyPDF SDK")

        Dim strInPDFFile As String = PDFFileName.Text

        If strInPDFFile = "" Then

            MsgBox("Please select a PDF file first")

            Return

        End If

        Dim strOutFile As String = Application.StartupPath() & "\modified.pdf"

        Dim nDPI As Integer = 72

        If LeftBox.Text = "" Then

            MsgBox("Please input a correct 'Left' value for text which you want to replace")

            Return

        End If

        If TopBox.Text = "" Then

            MsgBox("Please input a correct 'Top' value for text which you want to replace")

            Return

        End If

        If WidthBox.Text = "" Then

            MsgBox("Please input a correct 'Width' value for text which you want to replace")

            Return

        End If

        If HeightBox.Text = "" Then

            MsgBox("Please input a correct 'Height' value for text which you want to replace")

            Return

        End If

 

 

        Dim left As Integer = CInt(LeftBox.Text)

        Dim top As Integer = CInt(TopBox.Text)

        Dim width As Integer = CInt(WidthBox.Text)

        Dim height As Integer = CInt(HeightBox.Text)

 

        Dim oldText As String = OldTextBox.Text

        If oldText = "" Then

            MsgBox("Please input a correct 'Old Text' value for text which you want to replace")

            Return

        End If

        Dim newText As String = NewTextBox.Text

        If newText = "" Then

            MsgBox("Please input a correct 'New Text' value for text which you want to replace")

            Return

        End If

 

        hPDF = VeryPDF_ModifyPDF_OpenFile(strInPDFFile, strOutFile)

 

        'Replace horizontal text contents

        nPage = 1

        x = left * 72.0 / nDPI

        y = top * 72.0 / nDPI

        w = width * 72.0 / nDPI

        h = height * 72.0 / nDPI

        strOldText = oldText

        strNewText = newText

        bRet = VeryPDF_ModifyPDF_ModifyText(hPDF, nPage, x, y, w, h, strOldText, strNewText)

 

        VeryPDF_ModifyPDF_CloseFile(hPDF)

        MsgBox("Replace Text in PDF file completed." & vbCrLf & "VeryPDF_ModifyPDF_ModifyText() return: " & CStr(bRet))

 

    End Sub

End Class

 

 

@VeryDOC

Convert Printer Spool SPL File to Fax TIFF File on Mac OS X

Wanna convert printer spool spl file to fax tiff file on Mac OS X? With the help of PCL to Image Converter for Mac, you can easily transfer SPL to TIFF on your Mac. It’s a professional and easy-to-use tool that specifically designed for Mac users to convert print file such as SPL, PCL, PXL, etc. to images such as TIFF, BMP, PNG, etc. It’s able to create fax TIFF file which is faxable and supplies six kinds of compression methods to compress the TIFF image.

What’s SPL file?

SPL is a type of printer spool file created by Windows NT/2000 spooler for each print job. Generally speaking, Windows NT/2000 spooler usually generates two spool files for each print job– one is SPL file (for drawing commands) and the other one is SHD file (for job settings).

SPL is also a appended file created by FutureSplash Animator for creating vector-based animations, which is the predecessor of Flash. SPL files can be opened by Adobe Flash Player and Adobe Flash CS5.

What’s TIFF file?

TIFF (Tagged Image File Format), also named TIF, is a common faxing image file format. TIFF file is highly compatible with Photoshop, GIMP, Paint Shop Pro, QuarkXPress, Adobe InDesign, etc.

How to convert printer spool spl file to fax tiff file on Mac OS X?

  • Download and install PCL to Image Converter for Mac.
  • Add SPL file for process—Open the GUI interface of PCL to Image Converter for Mac, click Add File(s) -> select source SPL file -> click open.
  • Choose a destination folder for the fax TIFF file—Click clip_image002-> select a folder in pop-up dialog box -> click choose to choose an output folder. You can also directly type path of objective folder in edit box Output Path.
  • Make settings for TIFF—Click Setting on GUI interface, and then select one of Faxable TIFF Class F on pop-up list Fax TIFF so that Y DPI of fax TIFF could be 98 or 196 accordingly; Click one on pop list Color Depth to set color depth of TIFF image as 1 bit, 8 bits or 24 bits; Choose one option on pop list Compression to edit compression mode of TIFF. Finally, click OK top enact the settings.

spl to tiff

  • Start the conversion—Click Convert to start the conversion from SPL to TIFF in Mac OS X.

For more details about how to convert spl to tiff image on Mac OS X with PCL to Image Converter for Mac, please leave your comments here or contact the support team of VeryDOC.

PDF to Flash Converter

Convert PDF to flash in batch with easy operations

To make your pdf document not boring and make it more attractive, you can try to convert pdf to flash which can be played locally or online. With the command line program VeryDOC PDF to Flash Converter, you can easily convert the document of pdf to flash with some easy operations.

PDF to Flash Converter is a stand-alone program which does not need any other third-party program and you just need to download it via clicking here and there is no installation steps required because you just need to extract the ZIP file to some location of your computer and then use it.

The executable file pdftoflash.exe will act the called program in the conversion from pdf to flash. If you don’t know how to use the program, please drag the file pdftoflash.exe into MS-DOS interface and hit Enter button to see its usage which is like the one shown in Figure 1.

usage of PDF to Flash Converter command line

                                                               Figure 1

By following the command line usage, you can start to write your own command line to convert pdf to flash. Please see the following examples:

  1. pdftoflash.exe -swfburst C:\in.pdf C:\out.swf
  2. pdftoflash.exe -swfmaxopt -mapfont C:\in.pdf C:\out.swf
  3. for %F in (D:\test\*.pdf) do "pdftoflash.exe" "%F" "%~dpnF.swf"
  4. for /r D:\test %F in (*.pdf) do "pdftoflash.exe" "%F" "~dpnF.swf"

The first command line example is for converting pdf to flash file and burst pdf file to single page SWF files with the command line option –swfburst.

The second command line is to convert pdf to flash document and compress and optimize SWF files automatically, map fonts by mapfont.ini file.

The third and the last command lines are used to convert pdf to flash in batch via script language.

After inputting the command line, please hit Enter button on the keyboard to run the conversion.

If you want to know more information about the program or want to purchase this powerful application, please enter the homepage of PDF to Flash Converter. If you have any other questions about this conversion or the program, please contact the support team of VeryDOC.

@VeryDOC

VeryDOC PDF Margin Crop—The page shears of PDF file

When you browse a PDF file, have you ever felt that the blank margin of PDF file is too big, which is a waste of paper if you want to print the document? If so, do you want to resolve this kind of problem? Please don’t worry, VeryDOC PDF Margin Crop will help you crop pdf page according to your needs.

As a page shears, PDF Margin Crop can remove pdf blank margin by GUI or command line program. This article aims at showing you the whole process to crop pdf page by using GUI application. But at first, you need to download the application to your computer and install it by clicking here.

After opening the application by double clicking its icon, you will see a user interface like the one shown in Figure 1. Please click Add File (s) button to open file picker window in which you can choose pdf file (s) and add it or them into the program. You can also drag and drop the file (s) into the program.

interface of PDF Margin Crop

                                                                     Figure 1

Please click Setting button to open Setting  window which is shown in Figure 2. If you crop pdf page in batches, please choose the saving mode in Save mode group box from the tree given options. Then please input the retain pdf blank margin in Retain minimum margin edit box.

set parameters to crop pdf page

                                                   Figure 2

The application also supports to remove speckles from PDF file and you just need to input the minimum speckle size in Remove speckles which size less than.

If you want to secure the cropped PDF file, please click Password Settings tab to input owner and user password for the target file. Then please click OK button to close the current window.

Click Convert PDFs button to save the target file in popup window and start to crop pdf page. Several seconds later, you will get the cropped PDF files in specified location.

If you have other questions about this product, please leave your messages here or contact the support team of VeryDOC.

DOC to Any Converter

Doc2Any SDK not working on Windows 2003

I make a test at VM sever2008 64bit.
It don't work.
I use the customer test project.
Command Line Information:

-log c:\\log.txt c:\\example.doc c:\\example.pdf

This test program shows the error information:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at WindowsFormsApplication1.Form1.DocToAnyRunCmd(String strCmdLine)
at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
WindowsFormsApplication1
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/TOOL/doc2any_sdk_C%23/WindowsFormsApplication1.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1434 (REDBITS.050727-1400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
============================================================
Hi,

We downloaded evaluation version of server and developer SDK and try to run the sample WindowsFormsApplication.exe on Windows 2003 server with OpenOffice. It generated VeryPDF printer drivers but we are getting a return value of 4.

Attached is your windows forms application of C# with additional Messageboxes to show logging. We added -useoffice 0 option in the strCmd string, instead of xxxxxx which was already there.

We did not see the open office option parameter if there is any in the readme.txt.

When we run the example without any changes to the sample code, with Microsoft Office, it works fine, but on windows 2003 server with open office the example get hang up (not responding).

We are in the process of evaluating the server sdk before buying the license and we are stuck right now.

Regards,

============================================================

doc2any is return following values,

1: conversion successful
-1: this application has been damaged
4: something is wrong in command line options
5: the trial version has expired
6: no input filename
7: can't find input files in batch conversion, e.g., *.pdf wildcard
other values are indicate something is wrong during conversion.

We suggest you may use command line version to print the detailed log information,

https://www.verydoc.com/doc2any_cmd.zip

after you downloaded it, please unzip it to a folder, run following command line,

doc2any.exe -debug -useoffice 0 C:\test.doc C:\out.pdf

if you still have same problem, please send to us the log message, after we checked the log message, we will figure out a solution to you asap.

VeryDOC
============================================================
Hi,

After removing the -useoffice 0 and adding -log option in sample application

strCmd = "-$ XXXXXXXXXXXXXXXXXXXX -log C:\\log1.txt C:\\example.doc C:\\example.pdf";

and copying the jodconverter-2.2.2 folder/files, the example.doc is still not converted to pdf and there was no return value from API call DocToAnyRunCmd (application hangs(Not responding)). Please find attached the log1.txt file.
============================================================

Please by following steps to try again,

1. Please kill all processes of soffice.exe from task manager first,

2. Run following command line to launch soffice.exe application and monitor 8100 port,

"C:\Program Files\OpenOffice.org 3\program\soffice.exe" -headless -nologo -norestore -nofirststartwizard -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager

3. Run doc2any to convert your DOC file to PDF file again.

If you still have same problem, please create a remote desktop account on your test machine, we will arrange our engineer to login your test machine and work on this problem for you asap,

We suggest you may share your PC or Server by TeamViewer, TeamViewer can be downloaded from following website,

http://www.teamviewer.com

after you installed TeamViewer, please email to us your TeamViewer's ID and Password, please also arrange your test machine running at 24 hours, after we logged into your test machine and solved the problem, we will send an email to you, then you can close the TeamViewer application.

VeryDOC
============================================================
Hi,

We were able to figure out what was the problem and found the way to do the conversion when OpenOffice is used.
By default, when the user logs in to the server, the soffice.exe is already started in task manager. Also, there were hanging verypdf printer drivers already created from previous conversion attempts.

By deleting the process(soffice.bin closes the soffice.exe as well) and removing the printer drivers, then running the demo app with strcmd as follows:

strCmd = "-$ XXXXXXXXXXXXXXXXXXXX -log C:\\log1.txt C:\\example.doc C:\\example.pdf";

we were able to convert the example doc to pdf and also log file helped us in debugging the problem, when we accidently did not put jodcconverter related jar files in the running folder.

We found that Doc2any sdk automatically creates the soffice.exe soffice.bin(processes) and verypdf printer drivers the very first time(though conversion is slow the first time) and then keeps on using them for subsequent conversions(which is pretty fast).

Thanks for your help.

Regards,
============================================================
Thanks for your great message, your information will helpful for our other customers in the future.

If we can be of any other assistance, please feel free to let us know.

Thank you and have a nice day!

VeryDOC