PDF to Word using Acrobat SDK - pdf

OS: Windows Server 2019, Acrobat Pro DC 2021.011
My C# program calls Acrobat converting PDF to Word.docx. I used the code from Jie:
How to convert PDF to Word using Acrobat SDK?
AcroPDDoc pdfd = new AcroPDDoc();
pdfd.Open(sourceDoc.FileFullPath);
Object jsObj = pdfd.GetJSObject();
Type jsType = pdfd.GetType();
//have to use acrobat javascript api because, acrobat
object[] saveAsParam = { "newFile.doc", "com.adobe.acrobat.doc", "", false, false };
var vrc = jsType.InvokeMember("saveAs",BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance,null, jsObj, saveAsParam, CultureInfo.InvariantCulture);
Every few days, the function does not create the word file and returns NULL: "var vrc = jsType.InvokeMember". Identifying the last good date Acrobat successfully created the docx file, I restore the Server from Backup. The Acrobat function works.
What may be causing this problem?
In the same StackOverflow post, Subhobroto posted WinPython code to convert PDF to Word. Using Python 10.3.2, Error
avDoc = Dispatch("AcroExch.AVDoc") # Connect to Adobe Acrobat
# Open the input pdf file
ret = avDoc.Open(pdfFN)
# Python Error
File "<COMObject AcroExch.AVDoc>", line 2, in Open
pywintypes.com_error: (-2147352562, 'Invalid number of parameters.', None, None)
What is the correct code?
Thanks for help.

Related

When generating a RMarkdown PDF from Shiny, PDF saving and printing is disabled

I am trying to generate a report from a Shiny app where the user can select either HTML or PDF. I am able to generate a PDF from my .rmd file (LaTex format) and everything looks good with the layout/formatting. However, the PDF is opened (using Foxit PDF Reader) with a filename other than what I specified in my downloadhandler. I am also unable to save or print the PDF through the Foxit Reader window. The file name that is output is RStudio-randomletters.pdf (ex: RStudio-FoZvSx.pdf).
Generating an html report works fine with no issues, generates the correct file name that I specified, and opens a window for me to save or rename the file.
It seems that the PDF is the only issue so I'm not sure if it is just related to reading the PDF in the Foxit Reader or if it is something else?
Update
Using Adobe Acrobat instead of Foxit allows me to now save and print, but I am still having issues with the file name for the PDF.
Here is the code for my downloadhandler
output$downloadReport <- downloadHandler(
filename = function() {
paste('Report', sep = '.', switch(
input$format, PDF = 'pdf', HTML = 'html'))},
content = function(file) {
out <- if (input$format == 'HTML'){rmarkdown::render('report.Rmd',
params = list(Name = input$Name,
Reference = input$Reference),
switch(input$format,
PDF = pdf_document(), HTML = html_document()),
envir = new.env(parent = globalenv()))}
else if (input$format == 'PDF'){rmarkdown::render('pdfreport2.Rmd',
params = list(Name = input$Name,
Reference = input$Reference),
switch(input$format,
PDF = pdf_document(), HTML = html_document()),
envir = new.env(parent = globalenv()))}
file.rename(out, file)})

Attaching file to PDF via Access VBA using Adobe SDK

I'm trying to automatically add an attachment to a PDF file through VBA.
From what I can tell it is possible to handle this through FileAttachment annotations.
Dim testAnno As Object
Dim props As Object
Set testAnno = jso.AddAnnot
Set props = testAnno.getProps
props.Type = "FileAttachment"
' Code to attach file to PDF as attachment ......
testAnno.setProps props
I've found the following example in the Adobe documentation so essentially looking for a VBA equivalent to this:
var annot = this.addAnnot({
page: 0
type: "FileAttachment",
point: [400,500],
author: "A. C. Robat",
contents: "Call Smith to get help on this paragraph.",
cAttachmentPath: "/d/a.pdf" ,
});

Could not write the file an assertation has failed in illustrator

I'm using adobe extend script for exporting a file into jpg format in adobe illustrator. when i'm performing an export operation, sometimes it shows "could not write the file. an assertation has failed" but not every time.
I'm using following code
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileSpec = new File(dest);
exportOptions.antiAliasing = true;
exportOptions.qualitySetting = 70;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
Is it part of code error or anything from the side of Illustrator? it doesn't occur at all time. does it seem to an OS or version problems? Although I'm using the latest version of illustrator.

Create PDF file with images in WinRT

How I can create PDF files from a list of image in WinRT. I found something similar for windows phone 8 here("Converting list of images to pdf in windows phone 8") But I am looking for a solution for windows 8. If anyone of having knowledge about this please share your thoughts with me.
Try http://jspdf.com/
This should work on WinJS, but I haven't tested it. In a XAML app you can try to host a web browser control with a jsPDF-enabled page.
ComponentOne has now released the same PDF library that they had in Windows Phone for Windows Runtime. Tho it's not open source, of course.
Amyuni PDF Creator for WinRT (a commercial library) could be used for this task. You can create a new PDF file by creating a new instance of the class AmyuniPDFCreator.IacDocument, then add new pages with the method AddPage, and add pictures to each page by using the method IacPage.CreateObject.
The code in C# for adding a picture to a page will look like this:
public IacDocument CreatePDFFromImage()
{
IacDocument pdfDoc = new IacDocument();
// Set the license key
pdfDoc.SetLicenseKey("Amyuni Tech.", "07EFCD0...C4FB9CFD");
IacPage targetPage = pdfDoc.GetPage(1); // A new document will always be created with an empty page
// Adding a picture to the current page
using (Stream imgStrm = await Windows.ApplicationModel.Package.Current.InstalledLocation.OpenStreamForReadAsync("pdfcreatorwinrt.png"))
{
IacObject oPic = page.CreateObject(IacObjectType.acObjectTypePicture, "MyPngPicture");
BinaryReader binReader = new BinaryReader(imgStrm);
byte[] imgData = binReader.ReadBytes((int)imgStrm.Length);
// The "ImageFileData" attribute has not been added yet to the online documentation
oPic.AttributeByName("ImageFileData").Value = imgData;
oPic.Coordinates = new Rect(100, 2000, 1200, 2000);
}
return pdfDoc;
}
Disclaimer: I currently work as a developer of the library
For an "open source" alternative it might be better for you to rely on a web service that creates the PDF file using one of the many open source libraries available.
I think this may help you if you want to convert an image (.jpg) file to a PDF file.
Its working in my lab.
string source = "image.jpg";
string destinaton = "image.pdf";
PdfDocument doc = new PdfDocument();
doc.Pages.Add(new PdfPage());
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
XImage img = XImage.FromFile(source);
xgr.DrawImage(img, 0, 0);
doc.Save(destinaton);
doc.Close();
Thanks.

Print one page of WebBrowser

I am trying to automate printing of intranet websites. Since this is an application that will be put on a specific user's computer, which will be run on an as-needed basis, I'd like it to be as un-disruptive as possible (in other words, not launching IE for each page). The catch is that I need to print the first page of the website and then print the whole website again, which will produce the first page two times. What is the best way to do this?
I have no problem getting it to loop through the pages that it needs to print, nor do I have a problem opening the page with webbrowser. I do, however, have a problem specifying a print range.
I also tried PrintDocument, but couldn't figure out how to get that to open within the form.
Thanks for any help that can be provided.
To download the pdf file, try this solution using iTextSharp:
ITextSharp HTML to PDF?
Except with one substitution if you want to save directly to a file
private MemoryStream createPDF(string html)
{
MemoryStream msOutput = new MemoryStream();
TextReader reader = new StringReader(html);
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 30, 30, 30, 30);
// step 2:
// we create a writer that listens to the document
// and directs a XML-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("c:\\my.pdf", FileMode.Create));
// step 3: we create a worker parse the document
HTMLWorker worker = new HTMLWorker(document);
// step 4: we open document and start the worker on the document
document.Open();
worker.StartDocument();
// step 5: parse the html into the document
worker.Parse(reader);
// step 6: close the document and the worker
worker.EndDocument();
worker.Close();
document.Close();
return msOutput;
}
Once the PDF is set up, try ghostscript to print one page:
Print existing PDF (or other files) in C#
If you start a shell execute of the process, you can use the command line arguments:
gsprint "filename.pdf" -from 1 - to 1
Alternatively, WebBrowser can just print the full page: http://msdn.microsoft.com/en-us/library/b0wes9a3.aspx
I can't find anything referencing that WebBrowser itself can print "From page X to Y" without a print dialog.
Since I'm facing a similar problem, here's an alternate solution:
This open source project turns HTML documents to PDF documents similar to iTextSharp (http://code.google.com/p/wkhtmltopdf/). We ended up not using iTextSharp because of several formatting issues with the way the site we wanted to print was laid out. We send command line arguments to turn the html downloaded using a webclient into a pdf file.
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultNetworkCredentials;
string htmlText = wc.DownloadString("http://websitehere.com);
Then, after turning to pdf, you can simply print the file:
Process p = new Process();
p.StartInfo.FileName = string.Format("{0}.pdf", fileLocation);
p.StartInfo.Verb = "Print";
p.Start();
p.WaitForExit();
(Apologies for C#, I'm more familiar with it than VB.NET, though it should be a simple conversion)