tab 1
此演示向您展示如何将 pdf 文档转换为 docx、xps、html、图像等。
upload
maximum file size: 1 mb. files accepted: pdf.
click here to browse files.
fileerrors
convert to
source file:
filename
target file type:
e-iceblue
如果这不是您想要的 demo,您可以通过填写表格获取免费定制 demo。
如您有与我们产品相关的其他技术问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。;销售相关的问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。。
tab 2
import com.spire.pdf.fileformat;
import com.spire.pdf.pdfdocument;
import com.spire.pdf.conversion.pdfstandardsconverter;
import com.spire.pdf.graphics.pdfimagetype;
import javax.imageio.imageio;
import java.awt.image.bufferedimage;
import java.io.file;
import java.io.ioexception;
public class pdfconvertdemo {
public void pdfconversion(string pdffile,string converttype) throws ioexception {
string outputfilename = "output";
pdfdocument pdf=new pdfdocument();
pdf.loadfromfile(pdffile);
pdfstandardsconverter standardsconverter = new pdfstandardsconverter(pdffile);
switch (converttype) {
case "docx":
outputfilename = ".docx";
pdf.savetofile(outputfilename, fileformat.docx);
break;
case "doc":
outputfilename = ".doc";
pdf.savetofile(outputfilename, fileformat.doc);
break;
case "xps":
outputfilename = ".xps";
pdf.savetofile(outputfilename, fileformat.xps);
break;
case "xlsx":
outputfilename = ".xlsx";
pdf.savetofile(outputfilename, fileformat.xlsx);
break;
case "postscript":
outputfilename = ".ps";
pdf.savetofile(outputfilename, fileformat.postscript);
break;
case "html":
outputfilename = ".html";
pdf.savetofile(outputfilename, fileformat.html);
break;
case "image":
bufferedimage image=null;
for (int i = 0; i < pdf.getpages().getcount(); i ) {
image= pdf.saveasimage(i, pdfimagetype.bitmap);
imageio.write(image,"png",new file(outputfilename i ".png"));
}
break;
case "svg":
outputfilename =".svg";
pdf.savetofile(outputfilename, fileformat.svg);
break;
case "tiff":
outputfilename = ".tiff";
pdf.savetotiff(outputfilename);
break;
case "pdfa1a":
outputfilename = ".pdf";
standardsconverter.topdfa1a(outputfilename);
break;
case "pdfa1b":
outputfilename = ".pdf";
standardsconverter.topdfa1b(outputfilename);
break;
case "pdfa2a":
outputfilename = ".pdf";
standardsconverter.topdfa2a(outputfilename);
break;
case "pdfa2b":
outputfilename = ".pdf";
standardsconverter.topdfa2b(outputfilename);
break;
case "pdfa3a":
outputfilename = ".pdf";
standardsconverter.topdfa3a(outputfilename);
break;
case "pdfa3b":
outputfilename = ".pdf";
standardsconverter.topdfa3b(outputfilename);
break;
}
pdf.close();
}
}
tab 3
using spire.pdf;
using spire.pdf.conversion;
using spire.pdf.graphics;
using system;
using system.drawing;
using system.drawing.imaging;
namespace demoonlinecode
{
class pdfconvertdemo
{
public void pdfconversions(string pdffile, string converttype)
{
string outputfilename = "output";
pdfdocument pdf = new pdfdocument();
pdf.loadfromfile(pdffile);
pdfstandardsconverter standardsconverter = new pdfstandardsconverter(pdffile);
switch (converttype)
{
case "docx":
outputfilename = ".docx";
pdf.savetofile(outputfilename, fileformat.docx);
break;
case "doc":
outputfilename = ".doc";
pdf.savetofile(outputfilename, fileformat.doc);
break;
case "xps":
outputfilename = ".xps";
pdf.savetofile(outputfilename, fileformat.xps);
break;
case "xlsx":
outputfilename = ".xlsx";
pdf.savetofile(outputfilename, fileformat.xlsx);
break;
case "postscript":
outputfilename = ".ps";
pdf.savetofile(outputfilename, fileformat.postscript);
break;
case "html":
outputfilename = ".html";
pdf.convertoptions.setpdftohtmloptions(true, false, 1, false);
pdf.savetofile(outputfilename, fileformat.html);
break;
case "image":
image image = null;
for (int i = 0; i < pdf.pages.count; i )
{
image = pdf.saveasimage(i, pdfimagetype.bitmap);
image.save(outputfilename i ".png",imageformat.png);
}
break;
case "svg":
outputfilename = ".svg";
pdf.savetofile(outputfilename, fileformat.svg);
break;
case "tiff":
outputfilename = ".tiff";
jointiffimages(saveasimage(pdf), outputfilename, encodervalue.compressionlzw);
break;
case "pdfa1a":
outputfilename = ".pdf";
standardsconverter.topdfa1a(outputfilename);
break;
case "pdfa1b":
outputfilename = ".pdf";
standardsconverter.topdfa1b(outputfilename);
break;
case "pdfa2a":
outputfilename = ".pdf";
standardsconverter.topdfa2a(outputfilename);
break;
case "pdfa2b":
outputfilename = ".pdf";
standardsconverter.topdfa2b(outputfilename);
break;
case "pdfa3a":
outputfilename = ".pdf";
standardsconverter.topdfa3a(outputfilename);
break;
case "pdfa3b":
outputfilename = ".pdf";
standardsconverter.topdfa3b(outputfilename);
break;
}
pdf.close();
}
private static image[] saveasimage(pdfdocument document)
{
image[] images = new image[document.pages.count];
for (int i = 0; i < document.pages.count; i )
{
//use the document.saveasimage() method save the pdf as image
images[i] = document.saveasimage(i);
}
return images;
}
private static imagecodecinfo getencoderinfo(string mimetype)
{
imagecodecinfo[] encoders = imagecodecinfo.getimageencoders();
for (int j = 0; j < encoders.length; j )
{
if (encoders[j].mimetype == mimetype)
return encoders[j];
}
throw new exception(mimetype " mime type not found in imagecodecinfo");
}
public static void jointiffimages(image[] images, string outfile, encodervalue compressencoder)
{
//use the save encoder
system.drawing.imaging.encoder enc = system.drawing.imaging.encoder.saveflag;
encoderparameters ep = new encoderparameters(2);
ep.param[0] = new encoderparameter(enc, (long)encodervalue.multiframe);
ep.param[1] = new encoderparameter(system.drawing.imaging.encoder.compression, (long)compressencoder);
image pages = images[0];
int frame = 0;
imagecodecinfo info = getencoderinfo("image/tiff");
foreach (image img in images)
{
if (frame == 0)
{
pages = img;
//save the first frame
pages.save(outfile, info, ep);
}
else
{
//save the intermediate frames
ep.param[0] = new encoderparameter(enc, (long)encodervalue.framedimensionpage);
pages.saveadd(img, ep);
}
if (frame == images.length - 1)
{
//flush and close.
ep.param[0] = new encoderparameter(enc, (long)encodervalue.flush);
pages.saveadd(ep);
}
frame ;
}
}
}
}