Last active
March 24, 2022 15:53
-
-
Save aspose-cloud/7b6fd21096e2fbbda3548cdd8c565b96 to your computer and use it in GitHub Desktop.
aspose.com blog gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document document = new Document(dataDir + "3DTest.pdf"); | |
HtmlSaveOptions options = new HtmlSaveOptions | |
{ | |
SplitIntoPages = false, | |
FixedLayout = true, | |
CompressSvgGraphicsIfAny = false, | |
SaveTransparentTexts = true, | |
SaveShadowedTextsAsTransparentTexts = true, | |
RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground, | |
PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml | |
}; | |
document.Save(dataDir + "3Doutput.html", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document(dataDir + "3D.pdf"); | |
using (FileStream imageStream = new FileStream(dataDir + "3DPDF.png", FileMode.Create)) | |
{ | |
// Create Resolution object | |
Resolution resolution = new Resolution(300); | |
// Create PNG device with specified attributes (Width, Height, Resolution) | |
PngDevice pngDevice = new PngDevice(resolution); | |
// Convert a particular page and save the image to stream | |
pngDevice.Process(pdfDocument.Pages[1], imageStream); | |
// Close stream | |
imageStream.Close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "ColorFillLayer.psd"; | |
string exportPath = dataDir + "ColorFillLayer_output.psd"; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
var fillLayer = (FillLayer)layer; | |
if (fillLayer.FillSettings.FillType != FillType.Color) | |
{ | |
throw new Exception("Wrong Fill Layer"); | |
} | |
var settings = (IColorFillSettings)fillLayer.FillSettings; | |
settings.Color = Color.Red; | |
fillLayer.Update(); | |
im.Save(exportPath); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string fileName = dataDir + "FillLayerGradient.psd"; | |
GradientType[] gradientTypes = new[] | |
{ | |
GradientType.Linear, GradientType.Radial, GradientType.Angle, GradientType.Reflected, GradientType.Diamond | |
}; | |
using (var image = Image.Load(fileName)) | |
{ | |
PsdImage psdImage = (PsdImage)image; | |
FillLayer fillLayer = (FillLayer)psdImage.Layers[0]; | |
GradientFillSettings fillSettings = (GradientFillSettings)fillLayer.FillSettings; | |
foreach (var gradientType in gradientTypes) | |
{ | |
fillSettings.GradientType = gradientType; | |
fillLayer.Update(); | |
psdImage.Save(fileName + "_" + gradientType.ToString() + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string outputFilePath = Path.Combine(dataDir, "output.psd"); | |
using (var image = new PsdImage(100, 100)) | |
{ | |
FillLayer colorFillLayer = FillLayer.CreateInstance(Aspose.PSD.FileFormats.Psd.Layers.FillSettings.FillType.Color); | |
colorFillLayer.DisplayName = "Color Fill Layer"; | |
image.AddLayer(colorFillLayer); | |
FillLayer gradientFillLayer = FillLayer.CreateInstance(Aspose.PSD.FileFormats.Psd.Layers.FillSettings.FillType.Gradient); | |
gradientFillLayer.DisplayName = "Gradient Fill Layer"; | |
image.AddLayer(gradientFillLayer); | |
FillLayer patternFillLayer = FillLayer.CreateInstance(Aspose.PSD.FileFormats.Psd.Layers.FillSettings.FillType.Pattern); | |
patternFillLayer.DisplayName = "Pattern Fill Layer"; | |
patternFillLayer.Opacity = 50; | |
image.AddLayer(patternFillLayer); | |
image.Save(outputFilePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add support of Fill layers: Pattern | |
string sourceFileName = dataDir + "PatternFillLayer.psd"; | |
string exportPath = dataDir + "PatternFillLayer_Edited.psd"; | |
double tolerance = 0.0001; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
FillLayer fillLayer = (FillLayer)layer; | |
PatternFillSettings fillSettings = (PatternFillSettings)fillLayer.FillSettings; | |
if (fillSettings.HorizontalOffset != -46 || | |
fillSettings.VerticalOffset != -45 || | |
fillSettings.PatternId != "a6818df2-7532-494e-9615-8fdd6b7f38e5" || | |
fillSettings.PatternName != "$$$/Presets/Patterns/OpticalSquares=Optical Squares" || | |
fillSettings.AlignWithLayer != true || | |
fillSettings.Linked != true || | |
fillSettings.PatternHeight != 64 || | |
fillSettings.PatternWidth != 64 || | |
fillSettings.PatternData.Length != 4096 || | |
Math.Abs(fillSettings.Scale - 50) > tolerance) | |
{ | |
throw new Exception("PSD Image was read wrong"); | |
} | |
// Editing | |
fillSettings.Scale = 300; | |
fillSettings.HorizontalOffset = 2; | |
fillSettings.VerticalOffset = -20; | |
fillSettings.PatternData = new int[] | |
{ | |
Color.Red.ToArgb(), Color.Blue.ToArgb(), Color.Blue.ToArgb(), | |
Color.Blue.ToArgb(), Color.Red.ToArgb(), Color.Blue.ToArgb(), | |
Color.Blue.ToArgb(), Color.Blue.ToArgb(), Color.Red.ToArgb() | |
}; | |
fillSettings.PatternHeight = 3; | |
fillSettings.PatternWidth = 3; | |
fillSettings.AlignWithLayer = false; | |
fillSettings.Linked = false; | |
fillSettings.PatternId = Guid.NewGuid().ToString(); | |
fillLayer.Update(); | |
break; | |
} | |
} | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document doc = new Document(dataDir + "Document.docx"); | |
TextWatermarkOptions options = new TextWatermarkOptions() | |
{ | |
FontFamily = "Arial", | |
FontSize = 36, | |
Color = Color.Black, | |
Layout = WatermarkLayout.Diagonal, | |
IsSemitrasparent = true | |
}; | |
doc.Watermark.SetText("CONFIDENTIAL", options); | |
doc.Save(dataDir + "AddTextWatermark_out.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] sourcesFiles = new string[] | |
{ | |
@"34992OStroke", | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".jpg"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new JpegOptions() { Quality = 85 }; | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] sourcesFiles = new string[] | |
{ | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".pdf"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new PdfOptions(); | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] sourcesFiles = new string[] | |
{ | |
@"34992OStroke", | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".png"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }; | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] sourcesFiles = new string[] | |
{ | |
@"34992OStroke", | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".psd"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new PsdOptions(); | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save base64 string in TXT file because string is long | |
FileInputStream fis = new FileInputStream(dataDir + "base64.txt"); | |
String base64 = IOUtils.toString(fis, "UTF-8"); | |
String base64ImageString = base64.replace("data:image/png;base64,", ""); | |
byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64ImageString); | |
String path = dataDir + "Base64 to Image.png"; | |
// Convert Base64 to PNG or JPG Image | |
FileOutputStream fos = new FileOutputStream(path); | |
try { | |
fos.write(imageBytes); | |
} | |
finally { | |
fos.close(); | |
} | |
BufferedImage readImage = null; | |
try { | |
readImage = ImageIO.read(new File(path)); | |
int h = readImage.getHeight(); | |
int w = readImage.getWidth(); | |
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(); | |
com.aspose.pdf.Page page = doc.getPages().add(); | |
com.aspose.pdf.Image image = new com.aspose.pdf.Image(); | |
image.setFile(path); | |
page.getPageInfo().setHeight(h); | |
page.getPageInfo().setWidth(w); | |
page.getPageInfo().getMargin().setBottom(0); | |
page.getPageInfo().getMargin().setTop(0); | |
page.getPageInfo().getMargin().setRight(0); | |
page.getPageInfo().getMargin().setLeft(0); | |
page.getParagraphs().add(image); | |
doc.save(dataDir + "Base64-to-PDF.pdf"); | |
} catch (Exception e) { | |
readImage = null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save base64 string in TXT file because string is long | |
FileInputStream fis = new FileInputStream(dataDir + "base64.txt"); | |
String base64 = IOUtils.toString(fis, "UTF-8"); | |
String base64ImageString = base64.replace("data:image/png;base64,", ""); | |
byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64ImageString); | |
// Convert Base64 to JPG or PNG Image | |
FileOutputStream fos = new FileOutputStream(dataDir + "Base64 to Image.jpg"); | |
//FileOutputStream fos = new FileOutputStream(dataDir + "Base64 to Image.png"); | |
try { | |
fos.write(imageBytes); | |
} | |
finally { | |
fos.close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Initialize empty PDF document | |
using (Document pdfDocument = new Document()) | |
{ | |
pdfDocument.Pages.Add(); | |
Aspose.Pdf.Image image = new Aspose.Pdf.Image(); | |
// Load sample BMP image file | |
image.File = dataDir + @"Sample.bmp"; | |
pdfDocument.Pages[1].Paragraphs.Add(image); | |
// Save output PDF document | |
pdfDocument.Save(dataDir + @"BMPtoPDF.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document pdfdoc = new Document(); | |
Page page = pdfdoc.Pages.Add(); | |
TextBoxField nameBox = new TextBoxField(pdfdoc, new Aspose.Pdf.Rectangle(275, 740, 440, 770)); | |
nameBox.PartialName = "nameBox1"; | |
nameBox.DefaultAppearance.FontSize = 10; | |
nameBox.Multiline = true; | |
Border nameBorder = new Border(nameBox); | |
nameBorder.Width = 1; | |
nameBox.Border = nameBorder; | |
nameBox.Characteristics.Border = System.Drawing.Color.Black; | |
nameBox.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red); | |
TextBoxField mrnBox = new TextBoxField(pdfdoc, new Aspose.Pdf.Rectangle(275, 718, 440, 738)); | |
mrnBox.PartialName = "Box1"; | |
mrnBox.DefaultAppearance.FontSize = 10; | |
Border mrnBorder = new Border(mrnBox); | |
mrnBorder.Width = 1; | |
mrnBox.Border = mrnBorder; | |
mrnBox.Characteristics.Border = System.Drawing.Color.Black; | |
mrnBox.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red); | |
// Add form fields to first page of PDF document | |
pdfdoc.Form.Add(nameBox, 1); | |
pdfdoc.Form.Add(mrnBox, 1); | |
//Add Radiobuttons at specific position coordinates in PDF | |
Aspose.Pdf.Table table = new Aspose.Pdf.Table(); | |
//Set position here | |
table.Left = 200; | |
table.Top = 300; | |
table.ColumnWidths = "120"; | |
page.Paragraphs.Add(table); | |
Aspose.Pdf.Row r1 = table.Rows.Add(); | |
Aspose.Pdf.Row r2 = table.Rows.Add(); | |
Aspose.Pdf.Cell c1 = r1.Cells.Add(); | |
Aspose.Pdf.Cell c2 = r2.Cells.Add(); | |
RadioButtonField rf = new RadioButtonField(page); | |
rf.PartialName = "radio"; | |
pdfdoc.Form.Add(rf, 1); | |
RadioButtonOptionField opt1 = new RadioButtonOptionField(); | |
RadioButtonOptionField opt2 = new RadioButtonOptionField(); | |
opt1.OptionName = "Yes"; | |
opt2.OptionName = "No"; | |
opt1.Width = 15; | |
opt1.Height = 15; | |
opt2.Width = 15; | |
opt2.Height = 15; | |
rf.Add(opt1); | |
rf.Add(opt2); | |
opt1.Border = new Border(opt1); | |
opt1.Border.Width = 1; | |
opt1.Border.Style = BorderStyle.Solid; | |
opt1.Characteristics.Border = System.Drawing.Color.Black; | |
opt1.DefaultAppearance.TextColor = System.Drawing.Color.Red; | |
opt1.Caption = new TextFragment("Yes"); | |
opt2.Border = new Border(opt1); | |
opt2.Border.Width = 1; | |
opt2.Border.Style = BorderStyle.Solid; | |
opt2.Characteristics.Border = System.Drawing.Color.Black; | |
opt2.DefaultAppearance.TextColor = System.Drawing.Color.Red; | |
opt2.Caption = new TextFragment("No"); | |
c1.Paragraphs.Add(opt1); | |
c2.Paragraphs.Add(opt2); | |
pdfdoc.Save(dataDir + "Fillable_PDF_Form.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
com.aspose.pdf.Document pdfdoc = new com.aspose.pdf.Document(); | |
com.aspose.pdf.Page page = pdfdoc.getPages().add(); | |
TextBoxField nameBox = new TextBoxField(pdfdoc, new com.aspose.pdf.Rectangle(275, 740, 440, 770)); | |
nameBox.setPartialName("nameBox1"); | |
nameBox.getDefaultAppearance().setFontSize(10); | |
nameBox.setMultiline(true); | |
com.aspose.pdf.Border nameBorder = new com.aspose.pdf.Border(nameBox); | |
nameBorder.setWidth(1); | |
nameBox.setBorder(nameBorder); | |
nameBox.getCharacteristics().setBorder(java.awt.Color.BLACK); | |
nameBox.setColor(com.aspose.pdf.Color.fromRgb(Color.RED)); | |
TextBoxField mrnBox = new TextBoxField(pdfdoc, new com.aspose.pdf.Rectangle(275, 718, 440, 738)); | |
mrnBox.setPartialName("Box1"); | |
mrnBox.getDefaultAppearance().setFontSize(10); | |
com.aspose.pdf.Border mrnBorder = new com.aspose.pdf.Border(mrnBox); | |
mrnBorder.setWidth(1); | |
mrnBox.setBorder(mrnBorder); | |
mrnBox.getCharacteristics().setBorder(java.awt.Color.BLACK); | |
mrnBox.setColor(com.aspose.pdf.Color.fromRgb(Color.RED)); | |
// Add form fields to first page of PDF document | |
pdfdoc.getForm().add(nameBox, 1); | |
pdfdoc.getForm().add(mrnBox, 1); | |
//Add Radiobuttons at specific position coordinates in PDF | |
com.aspose.pdf.Table table = new com.aspose.pdf.Table(); | |
//Set position here | |
table.setLeft(200); | |
table.setTop(300); | |
table.setColumnWidths("120"); | |
page.getParagraphs().add(table); | |
com.aspose.pdf.Row r1 = table.getRows().add(); | |
com.aspose.pdf.Row r2 = table.getRows().add(); | |
com.aspose.pdf.Cell c1 = r1.getCells().add(); | |
com.aspose.pdf.Cell c2 = r2.getCells().add(); | |
com.aspose.pdf.RadioButtonField rf = new com.aspose.pdf.RadioButtonField(page); | |
rf.setPartialName("radio"); | |
pdfdoc.getForm().add(rf, 1); | |
com.aspose.pdf.RadioButtonOptionField opt1 = new com.aspose.pdf.RadioButtonOptionField(); | |
com.aspose.pdf.RadioButtonOptionField opt2 = new com.aspose.pdf.RadioButtonOptionField(); | |
opt1.setOptionName("Yes"); | |
opt2.setOptionName("No"); | |
opt1.setWidth(15); | |
opt1.setHeight(15); | |
opt2.setWidth(15); | |
opt2.setHeight(15); | |
rf.add(opt1); | |
rf.add(opt2); | |
opt1.setBorder(new com.aspose.pdf.Border(opt1)); | |
opt1.getBorder().setWidth(1); | |
opt1.getBorder().setStyle(com.aspose.pdf.BorderStyle.Solid); | |
opt1.getCharacteristics().setBorder(java.awt.Color.BLACK); | |
opt1.getDefaultAppearance().setTextColor(java.awt.Color.RED); | |
opt1.setCaption(new com.aspose.pdf.TextFragment("Yes")); | |
opt2.setBorder(new com.aspose.pdf.Border(opt1)); | |
opt2.getBorder().setWidth(1); | |
opt2.getBorder().setStyle(com.aspose.pdf.BorderStyle.Solid); | |
opt2.getCharacteristics().setBorder(java.awt.Color.BLACK); | |
opt2.getDefaultAppearance().setTextColor(java.awt.Color.RED); | |
opt2.setCaption(new com.aspose.pdf.TextFragment("No")); | |
c1.getParagraphs().add(opt1); | |
c2.getParagraphs().add(opt2); | |
pdfdoc.save(dataDir + "Fillable_PDF_Form.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document(dataDir + "Fill_PDF_Form_Field.pdf"); | |
// Delete a particular field by name | |
pdfDocument.Form.Delete("nameBox1"); | |
dataDir = dataDir + "Delete_Form_Field.pdf"; | |
// Save modified document | |
pdfDocument.Save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir + "Fill_PDF_Form_Field.pdf"); | |
// Delete a particular field by name | |
pdfDocument.getForm().delete("nameBox1"); | |
dataDir = dataDir + "Delete_Form_Field.pdf"; | |
// Save modified document | |
pdfDocument.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document from disk. | |
Document doc = new Document(dataDir + "TestFile.docx"); | |
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.HTML); | |
opts.setHtmlVersion(HtmlVersion.HTML_5); | |
opts.setExportImagesAsBase64(true); | |
opts.setExportPageMargins(true); | |
doc.save(dataDir + "TestFile.html", opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize new PDF document | |
var doc = new Document(); | |
// Spcify path of input EMF image file | |
var imageFile = dataDir + "drawing.emf"; | |
var page = doc.Pages.Add(); | |
string file = imageFile; | |
FileStream filestream = new FileStream(file, FileMode.Open, FileAccess.Read); | |
BinaryReader reader = new BinaryReader(filestream); | |
long numBytes = new FileInfo(file).Length; | |
byte[] bytearray = reader.ReadBytes((int)numBytes); | |
Stream stream = new MemoryStream(bytearray); | |
var b = new Bitmap(stream); | |
// Specify page dimesion properties | |
page.PageInfo.Margin.Bottom = 0; | |
page.PageInfo.Margin.Top = 0; | |
page.PageInfo.Margin.Left = 0; | |
page.PageInfo.Margin.Right = 0; | |
page.PageInfo.Width = b.Width; | |
page.PageInfo.Height = b.Height; | |
var image = new Aspose.Pdf.Image(); | |
image.File = imageFile; | |
page.Paragraphs.Add(image); | |
//Save output PDF document | |
doc.Save(dataDir + "EMFtoPDF.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "input.emf"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".emz"; | |
using (var image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = new EmfRasterizationOptions() { PageSize = image.Size }; | |
image.Save(outFile, new EmfOptions() { VectorRasterizationOptions = vectorRasterizationOptions, Compress = true }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "example.emz"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".emf"; | |
using (var image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = new EmfRasterizationOptions { PageSize = image.Size }; | |
image.Save(outFile, new EmfOptions { VectorRasterizationOptions = vectorRasterizationOptions }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "example.emz"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".png"; | |
using (Image image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = (VectorRasterizationOptions)image.GetDefaultOptions(new object[] { Color.White, image.Width, image.Height }); | |
image.Save(outFile, new PngOptions() { VectorRasterizationOptions = vectorRasterizationOptions }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var stream = System.IO.File.OpenRead(dataDir + "Sample.epub")) | |
{ | |
// Create an instance of PdfEncryptionInfo | |
Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionInfo info = new Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionInfo("user" , "owner" , Aspose.Html.Rendering.Pdf.Encryption.PdfPermissions.AssembleDocument, Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionAlgorithm.RC4_128); | |
// Create an instance of the PdfSaveOptions | |
var options = new Aspose.Html.Saving.PdfSaveOptions(); | |
options.Encryption = info; | |
// Call the ConvertEPUB method to convert the EPUB to PDF. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, dataDir + "EPUBpasswordPDF.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "Sample.epub")) | |
{ | |
Aspose.Html.Saving.PdfSaveOptions options = new Aspose.Html.Saving.PdfSaveOptions(); | |
// Call the ConvertEPUB method to convert the EPUB to PDF | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, dataDir + "EPUBtoPDF.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read the source PDF form with FileAccess of Read and Write. | |
// We need ReadWrite permission because after modification, | |
// We need to save the updated contents in same document/file. | |
FileStream fs = new FileStream(dataDir + "Fill_PDF_Form_Field.pdf", FileMode.Open, FileAccess.ReadWrite); | |
// Instantiate Document instance | |
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs); | |
// Get values from all fields | |
foreach (Field formField in pdfDocument.Form) | |
{ | |
// If the fullname of field contains A1, perform the operation | |
if (formField.FullName.Contains("nameBox1")) | |
{ | |
// Cast form field as TextBox | |
TextBoxField textBoxField = formField as TextBoxField; | |
// Modify field value | |
textBoxField.Value = "Preserve Extended Features"; | |
} | |
} | |
// Save the updated document in save FileStream | |
pdfDocument.Save(); | |
// Close the File Stream object | |
fs.Close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate Document instance | |
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir + "Fill_PDF_Form_Field.pdf"); | |
// Get values from all fields | |
for (com.aspose.pdf.Field formField : pdfDocument.getForm().getFields()) | |
{ | |
// If the fullname of field contains nameBox1, perform the operation | |
if (formField.getFullName().contains("nameBox1")) | |
{ | |
// Cast form field as TextBox | |
TextBoxField textBoxField = (TextBoxField) formField; | |
// Modify field value | |
textBoxField.setValue("Preserve Extended Features"); | |
} | |
} | |
// Save the updated document | |
pdfDocument.save(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document doc = new Document(dataDir + "ExtractHighlightedText.pdf"); | |
// Loop through all the annotations | |
foreach (Annotation annotation in doc.Pages[1].Annotations) | |
{ | |
// Filter TextMarkupAnnotation | |
if (annotation is TextMarkupAnnotation) | |
{ | |
TextMarkupAnnotation highlightedAnnotation = annotation as TextMarkupAnnotation; | |
// Retrieve highlighted text fragments | |
TextFragmentCollection collection = highlightedAnnotation.GetMarkedTextFragments(); | |
foreach (TextFragment tf in collection) | |
{ | |
// Display highlighted text | |
Console.WriteLine(tf.Text); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open PDF document | |
Document pdfDocument = new Document(dataDir + "ExtractTextAll.pdf"); | |
// Access required page in PDF document | |
Page page = pdfDocument.Pages[1]; | |
// Create TextAbsorber object to extract text | |
TextAbsorber textAbsorber = new TextAbsorber(); | |
// Accept the absorber for specified page | |
page.Accept(textAbsorber); | |
// Get the extracted text | |
string extractedText = textAbsorber.Text; | |
// Create a writer and open the file | |
TextWriter tw = new StreamWriter(dataDir + "extracted-text.txt"); | |
// Write a line of text to the file | |
tw.WriteLine(extractedText); | |
// Close the stream | |
tw.Close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document(dataDir + "ExtractTextAll.pdf"); | |
// Create TextAbsorber object to extract text | |
TextAbsorber absorber = new TextAbsorber(); | |
absorber.TextSearchOptions.LimitToPageBounds = true; | |
absorber.TextSearchOptions.Rectangle = new Aspose.Pdf.Rectangle(100, 200, 250, 350); | |
// Accept the absorber for first page | |
pdfDocument.Pages[1].Accept(absorber); | |
// Get the extracted text | |
string extractedText = absorber.Text; | |
// Create a writer and open the file | |
TextWriter tw = new StreamWriter(dataDir + "extracted-text.txt"); | |
// Write a line of text to the file | |
tw.WriteLine(extractedText); | |
// Close the stream | |
tw.Close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open PDF document | |
Document pdfDocument = new Document(dataDir + "ExtractTextAll.pdf"); | |
// Create TextAbsorber object to extract text | |
TextAbsorber textAbsorber = new TextAbsorber(); | |
// Accept the absorber for all pages | |
pdfDocument.Pages.Accept(textAbsorber); | |
// Get the extracted text | |
string extractedText = textAbsorber.Text; | |
// Create a writer and open the file | |
TextWriter tw = new StreamWriter(dataDir + "extracted-text.txt"); | |
// Write a line of text to the file | |
tw.WriteLine(extractedText); | |
// Close the stream | |
tw.Close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document pdfDocument = new Document(dataDir + @"ITF-TTF Manual.pdf"); | |
TextFragmentAbsorber absorber = new TextFragmentAbsorber(new TextEditOptions(TextEditOptions.FontReplace.RemoveUnusedFonts)); | |
foreach (Page page in pdfDocument.Pages) | |
{ | |
page.Accept(absorber); | |
//Read something from fragments | |
count += absorber.TextFragments.Count; | |
absorber.Reset(); | |
page.FreeMemory(); | |
//GC.Collect(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document(dataDir + "Test.pdf"); | |
System.Text.StringBuilder builder = new System.Text.StringBuilder(); | |
// String to hold extracted text | |
string extractedText = ""; | |
foreach (Page pdfPage in pdfDocument.Pages) | |
{ | |
using (MemoryStream textStream = new MemoryStream()) | |
{ | |
// Create text device | |
TextDevice textDevice = new TextDevice(); | |
// Set text extraction options - set text extraction mode (Raw or Pure) | |
TextExtractionOptions textExtOptions = new | |
TextExtractionOptions(TextExtractionOptions.TextFormattingMode.MemorySaving); | |
textDevice.ExtractionOptions = textExtOptions; | |
// Convert a particular page and save text to the stream | |
textDevice.Process(pdfPage, textStream); | |
// Convert a particular page and save text to the stream | |
textDevice.Process(pdfDocument.Pages[1], textStream); | |
// Close memory stream | |
textStream.Close(); | |
// Get text from memory stream | |
extractedText = Encoding.Unicode.GetString(textStream.ToArray()); | |
} | |
builder.Append(extractedText); | |
} | |
dataDir = dataDir + "Memory_Text_Extracted.txt"; | |
// Save the extracted text in text file | |
File.WriteAllText(dataDir, builder.ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// open document | |
Document pdfDocument = new Document(dataDir + @"Test.pdf"); | |
// create TextAbsorber object to find all instances of the input search phrase | |
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@"\d{4}"); //like 1999-2020 // set text search option to specify regular expression usage | |
TextSearchOptions textSearchOptions = new TextSearchOptions(true); | |
textFragmentAbsorber.TextSearchOptions = textSearchOptions; | |
// accept the absorber for all the pages | |
pdfDocument.Pages.Accept(textFragmentAbsorber); | |
// get the extracted text fragments | |
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments; | |
// loop through the fragments | |
foreach (TextFragment textFragment in textFragmentCollection) | |
{ | |
Console.WriteLine(textFragment.Text); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document pdfDocument = new Document(dataDir + "Test.pdf"); | |
TableAbsorber absorber = new TableAbsorber(); | |
absorber.Visit(pdfDocument.Pages[1]); | |
foreach (AbsorbedTable table in absorber.TableList) | |
{ | |
foreach (AbsorbedRow row in table.RowList) | |
{ | |
foreach (AbsorbedCell cell in row.CellList) | |
{ | |
TextFragment textfragment = new TextFragment(); | |
TextFragmentCollection textFragmentCollection = cell.TextFragments; | |
foreach (TextFragment fragment in textFragmentCollection) | |
{ | |
Console.WriteLine(fragment.Text); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document(dataDir + "Fillable_PDF_Form.pdf"); | |
// Get the fields | |
TextBoxField textBoxField1 = pdfDocument.Form["nameBox1"] as TextBoxField; | |
TextBoxField textBoxField2 = pdfDocument.Form["Box1"] as TextBoxField; | |
// Fill form fields' values | |
textBoxField1.Value = "A quick brown fox jumped over a lazy dog."; | |
textBoxField2.Value = "A quick brown fox jumped over a lazy dog."; | |
// Get radio button field | |
RadioButtonField radioField = pdfDocument.Form["radio"] as RadioButtonField; | |
// Specify the index of radio button from group | |
radioField.Selected = 1; | |
dataDir = dataDir + "Fill_PDF_Form_Field.pdf"; | |
// Save updated document | |
pdfDocument.Save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir + "Fillable_PDF_Form.pdf"); | |
// Get the fields | |
TextBoxField textBoxField1 = (TextBoxField) pdfDocument.getForm().get("nameBox1"); | |
TextBoxField textBoxField2 = (TextBoxField) pdfDocument.getForm().get("Box1"); | |
// Fill form fields' values | |
textBoxField1.setValue("A quick brown fox jumped over a lazy dog."); | |
textBoxField2.setValue("A quick brown fox jumped over a lazy dog."); | |
// Get radio button field | |
RadioButtonField radioField = (RadioButtonField) pdfDocument.getForm().get("radio"); | |
// Specify the index of radio button from group | |
radioField.setSelected(1); | |
dataDir = dataDir + "Fill_PDF_Form_Field.pdf"; | |
// Save updated document | |
pdfDocument.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize an HTML document from the html file | |
using (var document = new Aspose.Html.HTMLDocument(dataDir + "document.html")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Bmp); | |
// Convert HTML to BMP | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, dataDir + "output.bmp"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize an HTML document from the html file | |
using (var document = new Aspose.Html.HTMLDocument(dataDir + "document.html")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Gif); | |
// Convert HTML to GIF | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, dataDir + "output.gif"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set up the page-size 7x7 inches and change the background color to light gray | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg) | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(7), Aspose.Html.Drawing.Length.FromInches(7)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.LightGray, | |
}; | |
// Call the ConvertHTML to convert 'document.html' into jpeg image | |
Aspose.Html.Converters.Converter.ConvertHTML(dataDir + "HTMLtoImage.html", options, dataDir + "HTMLtoJPG.jpg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize an HTML document from the html file | |
using (var document = new Aspose.Html.HTMLDocument(dataDir + "document.html")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png); | |
// Convert HTML to PNG | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, dataDir + "output.png"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input JPG file | |
String path = dataDir + "Aspose.jpg"; | |
// Initialize new PDF document | |
Document doc = new Document(); | |
// Add empty page in empty document | |
Page page = doc.Pages.Add(); | |
Aspose.Pdf.Image image = new Aspose.Pdf.Image(); | |
image.File = (path); | |
// Add image on a page | |
page.Paragraphs.Add(image); | |
// Save output PDF file | |
doc.Save(dataDir + "ImagetoPDF.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input JPG image file | |
String path = dataDir + "Aspose.jpg"; | |
System.Drawing.Image srcImage = System.Drawing.Image.FromFile(path); | |
// Read Height of input image | |
int h = srcImage.Height; | |
// Read Height of input image | |
int w = srcImage.Width; | |
// Initialize a new PDF document | |
Document doc = new Document(); | |
// Add an empty page | |
Page page = doc.Pages.Add(); | |
Aspose.Pdf.Image image = new Aspose.Pdf.Image(); | |
image.File = (path); | |
// Set page dimensions and margins | |
page.PageInfo.Height = (h); | |
page.PageInfo.Width = (w); | |
page.PageInfo.Margin.Bottom = (0); | |
page.PageInfo.Margin.Top = (0); | |
page.PageInfo.Margin.Right = (0); | |
page.PageInfo.Margin.Left = (0); | |
page.Paragraphs.Add(image); | |
// Save output PDF file | |
doc.Save(dataDir + "ImagetoPDF_HeightWidth.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Aspose.Pdf.Document pdfdoc = new Aspose.Pdf.Document(); | |
pdfdoc.Pages.Add(); | |
Aspose.Pdf.Forms.TextBoxField textBoxField = new Aspose.Pdf.Forms.TextBoxField(pdfdoc.Pages[1], new Aspose.Pdf.Rectangle(85, 750, 215, 770)); | |
textBoxField.PartialName = "textbox1"; | |
textBoxField.Value = "Text Box"; | |
//TextBoxField.Border = new Border(); | |
Border border = new Border(textBoxField); | |
border.Width = 2; | |
border.Dash = new Dash(1, 1); | |
textBoxField.Border = border; | |
textBoxField.DefaultAppearance.FontSize = 10; | |
textBoxField.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); | |
// Add field to the document | |
pdfdoc.Form.Add(textBoxField, 1); | |
string JS = @"var w = this.getField('" + textBoxField.PartialName + "'); var today = new Date(); w.value = today.toLocaleString();"; | |
pdfdoc.OpenAction = new JavascriptAction(JS); | |
pdfdoc.Save(dataDir + "JS_Form.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
com.aspose.pdf.Document pdfdoc = new com.aspose.pdf.Document(); | |
pdfdoc.getPages().add(); | |
TextBoxField textBoxField = new TextBoxField(pdfdoc.getPages().get_Item(1), new com.aspose.pdf.Rectangle(85, 750, 215, 770)); | |
textBoxField.setPartialName("textbox1"); | |
textBoxField.setValue("Text Box"); | |
//TextBoxField.Border = new Border(); | |
com.aspose.pdf.Border border = new com.aspose.pdf.Border(textBoxField); | |
border.setWidth(2); | |
border.setDash(new com.aspose.pdf.Dash(1, 1)); | |
textBoxField.setBorder(border); | |
textBoxField.getDefaultAppearance().setFontSize(10); | |
textBoxField.setColor(com.aspose.pdf.Color.fromRgb(java.awt.Color.GREEN)); | |
// Add field to the document | |
pdfdoc.getForm().add(textBoxField, 1); | |
String JS = "var w = this.getField('" + textBoxField.getPartialName() + "'); var today = new Date(); w.value = today.toLocaleString();"; | |
pdfdoc.setOpenAction(new com.aspose.pdf.JavascriptAction(JS)); | |
pdfdoc.save(dataDir + "JS_Form.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load a workbook | |
Workbook workbook = new Workbook(dataDir + "Merge_Range.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Specify a range | |
Range range = worksheet.Cells.CreateRange("A1:D4"); | |
range.Name = "Named_Range"; | |
// Get the range. | |
Range range1 = workbook.Worksheets.GetRangeByName("Named_Range"); | |
// Define a style object. | |
Style style = workbook.CreateStyle(); | |
// Set the alignment. | |
style.HorizontalAlignment = TextAlignmentType.Center; | |
// Create a StyleFlag object. | |
StyleFlag flag = new StyleFlag(); | |
// Make the relative style attribute ON. | |
flag.HorizontalAlignment = true; | |
// Apply the style to the range. | |
range1.ApplyStyle(style, flag); | |
// Input data into range. | |
range1[0, 0].PutValue("Aspose"); | |
// Merge range | |
range.Merge(); | |
// Save the workbook | |
workbook.Save(dataDir + "Merge_NamedRange.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a workbook | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Input data into C6 Cell. | |
worksheet.Cells[0, 0].PutValue("Merge Range"); | |
// Create a range | |
Range range = worksheet.Cells.CreateRange("A1:D4"); | |
// Merge range into a single cell | |
range.Merge(); | |
// Save the workbook | |
workbook.Save(dataDir + "Merge_Range.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a Workbook. | |
Workbook wbk = new Workbook(); | |
// Create a Worksheet and get the first sheet. | |
Worksheet worksheet = wbk.Worksheets[0]; | |
// Create a Cells object ot fetch all the cells. | |
Cells cells = worksheet.Cells; | |
// Merge some Cells (C6:E7) into a single C6 Cell. | |
cells.Merge(5, 2, 2, 3); | |
// Input data into C6 Cell. | |
worksheet.Cells[5, 2].PutValue("This is my value"); | |
// Create a Style object to fetch the Style of C6 Cell. | |
Style style = worksheet.Cells[5, 2].GetStyle(); | |
// Create a Font object | |
Font font = style.Font; | |
// Set the name. | |
font.Name = "Times New Roman"; | |
// Set the font size. | |
font.Size = 18; | |
// Set the font color | |
font.Color = System.Drawing.Color.Blue; | |
// Bold the text | |
font.IsBold = true; | |
// Make it italic | |
font.IsItalic = true; | |
// Set the backgrond color of C6 Cell to Red | |
style.ForegroundColor = System.Drawing.Color.Red; | |
style.Pattern = BackgroundType.Solid; | |
// Apply the Style to C6 Cell. | |
cells[5, 2].SetStyle(style); | |
// Save the Workbook. | |
wbk.Save(dataDir + "MergeCells.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document(dataDir + "Fill_PDF_Form_Field.pdf"); | |
// Get a field | |
TextBoxField textBoxField = pdfDocument.Form["nameBox1"] as TextBoxField; | |
// Modify field value | |
textBoxField.Value = "Changed Value"; | |
textBoxField.ReadOnly = true; | |
dataDir = dataDir + "ModifyFormField.pdf"; | |
// Save updated document | |
pdfDocument.Save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir + "Fill_PDF_Form_Field.pdf"); | |
// Get a field | |
TextBoxField textBoxField = (TextBoxField) pdfDocument.getForm().get("nameBox1"); | |
// Modify field value | |
textBoxField.setValue("Changed Value"); | |
textBoxField.setReadOnly(true); | |
dataDir = dataDir + "ModifyFormField.pdf"; | |
// Save updated document | |
pdfDocument.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize PDF output stream | |
using (System.IO.Stream pdfStream = System.IO.File.Open(dataDir + "OXPStoPDF.pdf", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) | |
// Initialize OXPS input stream | |
//using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "input.oxps", System.IO.FileMode.Open)) | |
using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "sample.oxps", System.IO.FileMode.Open)) | |
{ | |
// Load OXPS document form the stream | |
Aspose.Page.XPS.XpsDocument document = new Aspose.Page.XPS.XpsDocument(xpsStream, new Aspose.Page.XPS.XpsLoadOptions()); | |
// or load OXPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions() | |
{ | |
JpegQualityLevel = 100, | |
ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg, | |
TextCompression = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate, | |
}; | |
// Create rendering device for PDF format | |
Aspose.Page.XPS.Presentation.Pdf.PdfDevice device = new Aspose.Page.XPS.Presentation.Pdf.PdfDevice(pdfStream); | |
document.Save(device, options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize PDF output stream | |
using (System.IO.Stream pdfStream = System.IO.File.Open(dataDir + "OXPStoPDF.pdf", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) | |
// Initialize OXPS input stream | |
//using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "input.oxps", System.IO.FileMode.Open)) | |
using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "sample.oxps", System.IO.FileMode.Open)) | |
{ | |
// Load OXPS document form the stream | |
Aspose.Page.XPS.XpsDocument document = new Aspose.Page.XPS.XpsDocument(xpsStream, new Aspose.Page.XPS.XpsLoadOptions()); | |
// or load XPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions() | |
{ | |
JpegQualityLevel = 100, | |
ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg, | |
TextCompression = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate, | |
PageNumbers = new int[] {1} | |
}; | |
// Create rendering device for PDF format | |
Aspose.Page.XPS.Presentation.Pdf.PdfDevice device = new Aspose.Page.XPS.Presentation.Pdf.PdfDevice(pdfStream); | |
document.Save(device, options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "Sample.epub")) | |
{ | |
// Create an instance of the PdfSaveOptions with a custom page-size, margins and a background-color. | |
var options = new Aspose.Html.Saving.PdfSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(12), Aspose.Html.Drawing.Length.FromInches(10)), | |
Margin = new Aspose.Html.Drawing.Margin(Aspose.Html.Drawing.Length.FromInches(1),Aspose.Html.Drawing.Length.FromInches(1),Aspose.Html.Drawing.Length.FromInches(1),Aspose.Html.Drawing.Length.FromInches(1)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.AliceBlue, | |
}; | |
// Call the ConvertEPUB method to convert the EPUB to PDF. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, dataDir + "PageSetup.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoadOptions options = new LoadOptions(); | |
options.setPassword("aspose"); | |
// Load the document from disk. | |
Document doc = new Document(dataDir + "TestFile.docx" , options); | |
//Save the document in HTML format. | |
doc.save(dataDir + "DocxToHTML.html",SaveFormat.HTML); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input PNG file | |
String path = dataDir + "Aspose.png"; | |
System.Drawing.Image srcImage = System.Drawing.Image.FromFile(path); | |
int h = srcImage.Height; | |
int w = srcImage.Width; | |
// Initialize new Document | |
Document doc = new Document(); | |
Page page = doc.Pages.Add(); | |
Aspose.Pdf.Image image = new Aspose.Pdf.Image(); | |
image.File = (path); | |
// Set page dimensions | |
page.PageInfo.Height = (h); | |
page.PageInfo.Width = (w); | |
page.PageInfo.Margin.Bottom = (0); | |
page.PageInfo.Margin.Top = (0); | |
page.PageInfo.Margin.Right = (0); | |
page.PageInfo.Margin.Left = (0); | |
page.Paragraphs.Add(image); | |
// Save output PDF | |
doc.Save(dataDir + "ImagetoPDF.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var files = new List<string>(); | |
files.Add(dataDir + "First.pdf"); | |
files.Add(dataDir + "Second.pdf"); | |
foreach (String file in files) | |
{ | |
//Create PdfViewer object | |
PdfViewer viewer = new PdfViewer(); | |
//Open input PDF file | |
viewer.BindPdf(file); | |
//Print PDF document | |
viewer.PrintDocument(); | |
//Close PDF file | |
viewer.Close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Aspose.Pdf.Facades.PdfViewer pdfv = new Aspose.Pdf.Facades.PdfViewer(); | |
pdfv.PdfQueryPageSettings += PdfvOnPdfQueryPageSettings; | |
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings(); | |
System.Drawing.Printing.PrinterSettings prin = new System.Drawing.Printing.PrinterSettings(); | |
pdfv.BindPdf(dataDir + "Print-PageRange.pdf"); | |
prin.PrinterName = "HP LaserJet M9050 MFP PCL6"; | |
prin.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169); | |
Aspose.Pdf.Facades.PdfPageEditor pageEditor = new Aspose.Pdf.Facades.PdfPageEditor(); | |
pageEditor.BindPdf(dataDir + "input.pdf"); | |
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0); | |
pgs.PaperSize = prin.DefaultPageSettings.PaperSize; | |
pdfv.PrintDocumentWithSettings(pgs, prin); | |
pdfv.Close(); | |
private static void PdfvOnPdfQueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs queryPageSettingsEventArgs, PdfPrintPageInfo currentPageInfo) | |
{ | |
bool isOdd = currentPageInfo.PageNumber % 2 != 0; | |
System.Drawing.Printing.PrinterSettings.PaperSourceCollection paperSources = queryPageSettingsEventArgs.PageSettings.PrinterSettings.PaperSources; | |
if (isOdd) | |
queryPageSettingsEventArgs.PageSettings.PaperSource = paperSources[0]; | |
else | |
queryPageSettingsEventArgs.PageSettings.PaperSource = paperSources[1]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create PdfViewer object | |
PdfViewer viewer = new PdfViewer(); | |
//Open input PDF file | |
viewer.BindPdf(dataDir + "Test.pdf"); | |
//Print PDF document | |
viewer.PrintDocument(); | |
//Close PDF file | |
viewer.Close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document doc = new Document("Test.pdf"); | |
PdfViewer viewer = new PdfViewer(); | |
viewer.BindPdf(doc); | |
viewer.PrinterJobName = System.IO.Path.GetFileName(doc.FileName); | |
viewer.Resolution = 110; | |
// Set attributes for printing | |
viewer.AutoResize = true; // Print the file with adjusted size | |
viewer.AutoRotate = false; // Print the file with adjusted rotation | |
viewer.PrintPageDialog = false; // Do not produce the page number dialog when printing | |
viewer.RenderingOptions.UseNewImagingEngine = true; | |
// Create objects for printer and page settings and PrintDocument | |
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings(); | |
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings(); | |
// Set printer name | |
ps.PrinterName = "Microsoft Print to PDF"; | |
pgs.PaperSize = new System.Drawing.Printing.PaperSize(paperTypeName, paperWidth, paperHeight); | |
pgs.Margins = new System.Drawing.Printing.Margins(margins.Left, margins.Right, margins.Top, margins.Bottom); | |
pgs.PaperSource = GetPaperSource(printerName, trayName); | |
// Print document using printer and page settings | |
viewer.PrintDocumentWithSettings(pgs, ps); | |
/// <summary> | |
/// Return the PaperSource object for the provided printer and tray name. | |
/// </summary> | |
/// <param name="printerName"></param> | |
/// <param name="trayName"></param> | |
/// <returns></returns> | |
public static System.Drawing.Printing.PaperSource GetPaperSource(string printerName, string trayName) | |
{ | |
System.Drawing.Printing.PaperSource ps = null; | |
System.Drawing.Printing.PrintDocument prtDoc = new System.Drawing.Printing.PrintDocument(); | |
prtDoc.PrinterSettings.PrinterName = printerName; | |
for (int i = 0; i < prtDoc.PrinterSettings.PaperSources.Count; i++) | |
{ | |
if (prtDoc.PrinterSettings.PaperSources[i].SourceName.ToLower().Equals(trayName.ToLower())) | |
{ | |
ps = prtDoc.PrinterSettings.PaperSources[i]; | |
break; | |
} | |
} | |
return ps; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate PdfViewer object | |
PdfViewer viewer = new PdfViewer(); | |
// Bind source PDF file | |
viewer.BindPdf(dataDir + "Sample Document with Bookmark.pdf"); | |
viewer.AutoResize = true; | |
// Hide printing dialog | |
viewer.PrintPageDialog = false; | |
// Create Printer Settings object | |
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings(); | |
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings(); | |
System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument(); | |
// Specify the printer anme | |
//ps.PrinterName = "Microsoft XPS Document Writer"; | |
ps.PrinterName = "Microsoft Print to PDF"; | |
// Resultant Printout name | |
//ps.PrintFileName = "ResultantPrintout.xps"; | |
ps.PrintFileName = "ResultantPrintout.pdf"; | |
// Print the output to file | |
ps.PrintToFile = true; | |
ps.FromPage = 1; | |
ps.ToPage = 2; | |
ps.PrintRange = System.Drawing.Printing.PrintRange.SomePages; | |
// Specify the page size of printout | |
pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169); | |
ps.DefaultPageSettings.PaperSize = pgs.PaperSize; | |
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0); | |
// Print the document with settings specified above | |
viewer.PrintDocumentWithSettings(pgs, ps); | |
// Check the print status | |
if (viewer.PrintStatus != null) | |
{ | |
// An exception was thrown | |
Exception ex = viewer.PrintStatus as Exception; | |
if (ex != null) | |
{ | |
// Get exception message | |
} | |
} | |
else | |
{ | |
// No errors were found. Printing job has completed successfully | |
Console.WriteLine("printing completed without any issue.."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Load secure PDF document while specifying User or Owner password | |
Document document = new Document(dataDir + "Password.pdf" , "userORowner"); | |
//Create PdfViewer object | |
PdfViewer viewer = new PdfViewer(); | |
//Open input PDF file | |
viewer.BindPdf(document); | |
//Print PDF document | |
viewer.PrintDocument(); | |
//Close PDF file | |
viewer.Close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string inPdf = dataDir + "Test.pdf"; | |
string output = dataDir; | |
IList<PrintingJobSettings> printingJobs = new List<PrintingJobSettings>(); | |
PrintingJobSettings printingJob1 = new PrintingJobSettings(); | |
printingJob1.FromPage = 2; | |
printingJob1.ToPage = 3; | |
printingJobs.Add(printingJob1); | |
PrintingJobSettings printingJob2 = new PrintingJobSettings(); | |
printingJob2.FromPage = 5; | |
printingJob2.ToPage = 7; | |
printingJobs.Add(printingJob2); | |
{ | |
for (var printingJobIndex = 0; printingJobIndex < printingJobs.Count; printingJobIndex++) | |
{ | |
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings(); | |
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings(); | |
ps.PrinterName = "Microsoft Print to PDF"; | |
ps.PrintRange = System.Drawing.Printing.PrintRange.SomePages; | |
ps.FromPage = printingJobs[printingJobIndex].FromPage; | |
ps.ToPage = printingJobs[printingJobIndex].ToPage; | |
System.Console.WriteLine(ps.FromPage); | |
System.Console.WriteLine(ps.ToPage); | |
System.Console.WriteLine(printingJobIndex); | |
using (var theViewer = new Aspose.Pdf.Facades.PdfViewer()) | |
{ | |
// Document printing code goes here | |
// Print document using printer and page settings | |
theViewer.BindPdf(inPdf); | |
theViewer.AutoResize = true; | |
theViewer.AutoRotate = true; | |
theViewer.PrintPageDialog = false; | |
theViewer.PrintDocumentWithSettings(pgs, ps); | |
theViewer.Close(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System::String filePub = dataDir() + u"1.pub"; | |
System::String filePdf = dataDir() + u"1.pdf"; | |
System::Console::WriteLine(u"Convert starting..."); | |
System::SharedPtr<IPubParser> parser = PubFactory::CreateParser(filePub); | |
System::SharedPtr<Document> document = parser->Parse(); | |
PubFactory::CreatePdfConverter()->ConvertToPdf(document, filePdf); | |
System::Console::WriteLine(u"Convert done."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document doc = new Document(dataDir + "AddTextWatermark_out.docx"); | |
if (doc.Watermark.Type == WatermarkType.Text) | |
{ | |
doc.Watermark.Remove(); | |
} | |
doc.Save(dataDir + "RemoveWatermark_out.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "Example.svg"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".svgz"; | |
using (var image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = new SvgRasterizationOptions() { PageSize = image.Size }; | |
image.Save(outFile, new SvgOptions() { VectorRasterizationOptions = vectorRasterizationOptions, Compress = true }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "example.svgz"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".png"; | |
using (Image image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = (VectorRasterizationOptions)image.GetDefaultOptions(new object[] { Color.White, image.Width, image.Height }); | |
image.Save(outFile, new PngOptions() { VectorRasterizationOptions = vectorRasterizationOptions }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "example.svgz"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".svg"; | |
using (var image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = new SvgRasterizationOptions() { PageSize = image.Size }; | |
image.Save(outFile, new SvgOptions() { VectorRasterizationOptions = vectorRasterizationOptions }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initalize new Document | |
Document pdf = new Document(); | |
//Load TIFF image into stream | |
MemoryStream ms = new MemoryStream(); | |
new FileStream(dataDir + @"Aspose.tiff", FileMode.Open).CopyTo(ms); | |
Bitmap myimage = new Bitmap(ms); | |
// Convert multi page or multi frame TIFF to PDF | |
FrameDimension dimension = new FrameDimension(myimage.FrameDimensionsList[0]); | |
int frameCount = myimage.GetFrameCount(dimension); | |
// Iterate through each frame | |
for (int frameIdx = 0; frameIdx <= frameCount - 1; frameIdx++) | |
{ | |
Page sec = pdf.Pages.Add(); | |
myimage.SelectActiveFrame(dimension, frameIdx); | |
MemoryStream currentImage = new MemoryStream(); | |
myimage.Save(currentImage, ImageFormat.Tiff); | |
Aspose.Pdf.Image imageht = new Aspose.Pdf.Image(); | |
imageht.ImageStream = currentImage; | |
sec.Paragraphs.Add(imageht); | |
} | |
// Save output PDF file | |
pdf.Save(dataDir + "TifftoPDF.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a workbook | |
Workbook workbook = new Workbook(dataDir + "Merge_Range.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Create a range | |
Range range = worksheet.Cells.CreateRange("A1:D4"); | |
// UnMerge range | |
range.UnMerge(); | |
// Save the workbook | |
workbook.Save(dataDir + "UnmergeRange.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open the excel file. | |
Workbook wbk = new Workbook(dataDir + "MergeCells.xlsx"); | |
// Create a Worksheet and get the first sheet. | |
Worksheet worksheet = wbk.Worksheets[0]; | |
// Create a Cells object ot fetch all the cells. | |
Cells cells = worksheet.Cells; | |
// Unmerge the cells. | |
cells.UnMerge(5, 2, 2, 3); | |
// Save the file. | |
wbk.Save(dataDir + "UnmergeCells.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document doc = new Document(dataDir + "Document.doc"); | |
ImageWatermarkOptions options = new ImageWatermarkOptions() | |
{ | |
IsWashout = false | |
}; | |
doc.Watermark.SetImage(Image.FromFile(dataDir + "Watermark.jpg"), options); | |
doc.Save(dataDir + "AddImageWatermark_out.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "castle.wmf"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".wmz"; | |
using (var image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = new WmfRasterizationOptions() { PageSize = image.Size }; | |
image.Save(outFile, new WmfOptions() { VectorRasterizationOptions = vectorRasterizationOptions, Compress = true }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "example.wmz"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".png"; | |
using (Image image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = (VectorRasterizationOptions)image.GetDefaultOptions(new object[] { Color.White, image.Width, image.Height }); | |
image.Save(outFile, new PngOptions() { VectorRasterizationOptions = vectorRasterizationOptions }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string file = "example.wmz"; | |
string inputFile = dataDir + file; | |
string outFile = inputFile + ".wmf"; | |
using (var image = Image.Load(inputFile)) | |
{ | |
VectorRasterizationOptions vectorRasterizationOptions = new WmfRasterizationOptions() { PageSize = image.Size }; | |
image.Save(outFile, new WmfOptions() { VectorRasterizationOptions = vectorRasterizationOptions }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document from disk. | |
Document doc = new Document(dataDir + "TestFile.docx"); | |
// Save the document into HTML. | |
doc.save(dataDir + "Document_out.html", SaveFormat.HTML); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load word document from disk. | |
Document doc = new Document(dataDir + "TestFile.docx"); | |
// Save the document into MHTML. | |
doc.save(dataDir + "Document.mhtml", SaveFormat.MHTML); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate Document object | |
Document doc = new Document(); | |
// Bind source XML file | |
doc.BindXml(dataDir + "XML.xml"); | |
// Convert XML to PDF | |
doc.Save(dataDir + "XMLToPDF.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create pdf document | |
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(); | |
//Bind XML and XSLT files to the document | |
try | |
{ | |
pdf.BindXml(dataDir + "\\HelloWorld.xml", dataDir + "\\HelloWorld.xslt"); | |
} | |
catch (System.Exception) | |
{ | |
throw; | |
} | |
//Save the document | |
pdf.Save(dataDir + "HelloWorldUsingXmlAndXslt.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize PDF output stream | |
using (System.IO.Stream pdfStream = System.IO.File.Open(dataDir + "XPStoPDF.pdf", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) | |
// Initialize XPS input stream | |
//using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "input.xps", System.IO.FileMode.Open)) | |
using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "sample.xps", System.IO.FileMode.Open)) | |
{ | |
// Load XPS document form the stream | |
Aspose.Page.XPS.XpsDocument document = new Aspose.Page.XPS.XpsDocument(xpsStream, new Aspose.Page.XPS.XpsLoadOptions()); | |
// or load XPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions() | |
{ | |
JpegQualityLevel = 100, | |
ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg, | |
TextCompression = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate, | |
}; | |
// Create rendering device for PDF format | |
Aspose.Page.XPS.Presentation.Pdf.PdfDevice device = new Aspose.Page.XPS.Presentation.Pdf.PdfDevice(pdfStream); | |
document.Save(device, options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize PDF output stream | |
using (System.IO.Stream pdfStream = System.IO.File.Open(dataDir + "XPStoPDF.pdf", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) | |
// Initialize XPS input stream | |
//using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "input.xps", System.IO.FileMode.Open)) | |
using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "sample.xps", System.IO.FileMode.Open)) | |
{ | |
// Load XPS document form the stream | |
Aspose.Page.XPS.XpsDocument document = new Aspose.Page.XPS.XpsDocument(xpsStream, new Aspose.Page.XPS.XpsLoadOptions()); | |
// or load XPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions() | |
{ | |
JpegQualityLevel = 100, | |
ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg, | |
TextCompression = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate, | |
PageNumbers = new int[] {1, 3} | |
}; | |
// Create rendering device for PDF format | |
Aspose.Page.XPS.Presentation.Pdf.PdfDevice device = new Aspose.Page.XPS.Presentation.Pdf.PdfDevice(pdfStream); | |
document.Save(device, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment