C # core code
Public static void ConvertPDF2Image (string pdfInputPath, string imageOutputPath,
String imageName, int startPageNum, int endPageNum, ImageFormat ImageFormat, double resolution)
{
StreamWriter sw=new StreamWriter (" E: \ \ test. TXT ", false, Encoding. The ASCII);
Acrobat. CAcroPDDoc pdfDoc=null;
Acrobat. CAcroPDPage pdfPage=null;
Acrobat. CAcroRect pdfRect=null;
Acrobat. CAcroPoint pdfPoint=null;
//Create the document (Can only Create the AcroExch. PDDoc object using newest - binding)
//Note using visual basic helper functions provides, have to add the reference to the DLL
PdfDoc=(Acrobat. CAcroPDDoc) Microsoft. VisualBasic. Interaction. The CreateObject (" AcroExch. PDDoc ", "");
//validate parameter
if (! PdfDoc. Open (pdfInputPath)) {throw new FileNotFoundException (); }
if (! Directory. The Exists (imageOutputPath)) {Directory. CreateDirectory (imageOutputPath); }
If (startPageNum & lt;=0) {startPageNum=1; }
If (endPageNum & gt; PdfDoc. GetNumPages () | | endPageNum & lt; .=0) {endPageNum=pdfDoc GetNumPages (); }
If (startPageNum & gt; EndPageNum) {int tempPageNum=startPageNum; StartPageNum=endPageNum; EndPageNum=startPageNum; }
If (imageFormat==null) {imageFormat=imageFormat. Jpeg; }
If (resolution & lt;=0) {resolution=1; }
//start to convert each page
For (int I=startPageNum; i <=endPageNum; I++)
{
PdfPage=(Acrobat. CAcroPDPage) pdfDoc. AcquirePage (I - 1);
PdfPoint=(Acrobat. CAcroPoint) pdfPage. GetSize ();
PdfRect=(Acrobat. CAcroRect) Microsoft. VisualBasic. Interaction. The CreateObject (" AcroExch. The Rect ", "");
Int imgWidth=(int) ((double) pdfPoint. X * resolution).
Int imgHeight=(int) ((double) pdfPoint. Y * resolution).
sw. WriteLine (" world ");
PdfRect. Left=0;
PdfRect. Right=(short) imgWidth;
PdfRect. Top=0;
PdfRect. Bottom=(short) imgHeight;
//Render to the clipboard, scaled by 100 percent (ie., the original size)
//my we want a smaller image, better for us to scale in the.net
//than Acrobat as it order to Greek out small text
PdfPage. CopyToClipboard (pdfRect, 0, 0, (short) resolution (100 *));
IDataObject clipboardData=(https://bbs.csdn.net/topics/Clipboard.GetDataObject);
If (clipboardData. GetDataPresent (DataFormats. Bitmap))
{
Bitmap pdfBitmap=(Bitmap) clipboardData. GetData (DataFormats. Bitmap);
Bine pdfBitmap. Save (Path.Com (imageOutputPath, imageName) + i.T oString () + "" + imageFormat. The ToString (), imageFormat);
PdfBitmap. The Dispose ();
}
}
PdfDoc. Close ();
Marshal. ReleaseComObject (pdfPage);
Marshal. ReleaseComObject (pdfRect);
Marshal. ReleaseComObject (pdfDoc);
Marshal. ReleaseComObject (pdfPoint);
}
MFC calling code
Program: : ConvertPDF2Image (str_pdf, "E: \ \ data1 \ ", "", 0, 0, ImageFormat: : Jpeg, 1);
CodePudding user response:
A great god the great god to bowl!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!CodePudding user response:
Great god the great god the great god the great godCodePudding user response:
StreamWriter is.net dongdong,Please change to CFile
CodePudding user response: